-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPrices.py
More file actions
182 lines (135 loc) · 3.97 KB
/
CheckPrices.py
File metadata and controls
182 lines (135 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import requests
from bs4 import BeautifulSoup
import smtplib
import schedule
import threading
import time
import re
import random
def generateHeaders():
header = {"User-Agent": f'Mozilla/5.0 (Windows NT 10.0; Win32; x32) AppleWebKit/597.36 (KHTML, like Gecko) Chrome/90.0.{random.randint(0,9)}{random.randint(0,9)}{random.randint(0,9)}{random.randint(0,9)}.163 Safari/507.36'}
print(header)
return header
class Queue(object):
def __init__(self):
self.item = []
def __repr__(self):
return "{}".format(self.item)
def __str__(self):
return "{}".format(self.item)
def enque(self, add):
self.item.insert(0, add)
return True
def size(self):
return len(self.item)
def isEmpty(self):
if self.size == 0:
return True
else:
return False
def deque(self):
if self.size == 0:
return None
else:
return self.item.pop()
global queue
queue = Queue()
priceList = []
def add_prices(*prices):
# print(sum(prices))
return sum(prices)
def checkPrice(url):
global priceList
page = requests.get(url, headers=generateHeaders())
soup = BeautifulSoup(page.content, 'html.parser')
price = soup.find("span", {"id": "priceblock_ourprice"})
div = price.text
print(price)
# converted_price = div[1:8]
k = div.replace(",", "")
z = k.replace("₹", "")
w = z.replace(" ", "")
x = " ".join(w.split())
price = x.replace(".00", "")
converted_price = int(price)
souptitle = soup.find("span", {"id": "productTitle"}).text
title = souptitle.replace('\n', '')
dic = {
"title": title,
"price": converted_price
}
priceList.append(dic)
if len(priceList)==7:
return returnFunc()
# print(priceList)
# queue.enque(priceList)
mainPriceList = []
def returnFunc():
Normal = []
superList = []
TiList = []
for price in priceList:
sentence = price['title']
price = price["price"]
Normal.append(price)
superList.append(price)
TiList.append(price)
if re.search(r'\b1660Ti\b', sentence):
TiPrice = price
if re.search(r'\bGeForce GTX 1660 Twin\b', sentence):
NormalPrice = price
if re.search(r'\b1660 Super Overclocked\b', sentence):
SuperPrice = price
Normal.remove(TiPrice)
Normal.remove(SuperPrice)
superList.remove(NormalPrice)
superList.remove(TiPrice)
TiList.remove(NormalPrice)
TiList.remove(SuperPrice)
normalTup = tuple(Normal)
superTup = tuple(superList)
TiTup = tuple(TiList)
priceNormal = add_prices(*normalTup)
priceSuper = add_prices(*superTup)
priceTi = add_prices(*TiTup)
dic = {
"Normal price with 1660 is:": priceNormal,
"Super price with 1660 Super is:": priceSuper,
"Ti price with 1660Ti is:": priceTi
}
# queue.enque(dic)
# print(dic)
mainPriceList.append(dic)
queue.enque(dic)
# return dic
def start(url):
thread = threading.Thread(target=checkPrice, args=(url,))
thread.start()
# thread.join()
# while True:
# flag = queue.isEmpty()
# if flag:
# pass
# else:
# thread.join()
# queue.deque()
# print(priceList)
# break
urlList = ["https://www.amazon.in/Zotac-GeForce-1660-GDDR6-Graphic/dp/B07NMWQXLR",
"https://www.amazon.in/Kingston-Internal-2000MB-SA2000M8-500G/dp/B07VXCFNVS/",
"https://www.amazon.in/gp/product/B07MV9BMNY/",
"https://www.amazon.in/gp/product/B07B4GNMS9/",
"https://www.amazon.in/gp/product/B07STGGQ18/",
"https://www.amazon.in/gp/product/B07PPPHQYX/",
"https://www.amazon.in/gp/product/B081SPGMBD/"]
def start_trecking():
for url in urlList:
start(url)
time.sleep(5)
dic = {
"TotPrice": mainPriceList,
"priceList": priceList
}
# print(dic)
return dic
# start_trecking()