-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathFireFoxTest.py
More file actions
70 lines (52 loc) · 1.71 KB
/
Copy pathFireFoxTest.py
File metadata and controls
70 lines (52 loc) · 1.71 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
import time
from selenium import webdriver
import pagerduty
class PagePoller:
def __init__(self, url):
self.url = url
self.createBrowser()
def checkAvailable(self):
addToCartButton = addButton = self.driver.find_element_by_class_name("add-to-cart-button")
if ("btn-disabled" in addToCartButton.get_attribute("class")):
return False
else:
addToCartButton.click()
return True
def createBrowser(self):
self.driver = webdriver.Firefox()
self.driver.get(self.url)
def refreshPage(self):
self.driver.close()
self.driver.quit()
self.createBrowser()
textFile = open("bestbuy-links1.txt", "r")
lines = textFile.readlines()
print(lines)
pages = []
for u in lines:
pages.append(PagePoller(u))
while True:
toRemove = []
for p in pages:
if (p.checkAvailable()):
pagerduty.sendPagerDutyAlert()
toRemove.append(p)
else:
p.refreshPage()
for p in toRemove:
pages.remove(p)
#time.sleep(0)
#
# #driver = webdriver.Firefox()
#
# # happy case - item is available
# #driver.get("https://www.bestbuy.com/site/nvidia-titan-rtx-24gb-gddr6-pci-express-3-0-graphics-card/6320585.p?skuId=6320585")
#
#
# #driver.get("https://www.bestbuy.com/site/nvidia-geforce-rtx-3080-10gb-gddr6x-pci-express-4-0-graphics-card-titanium-and-black/6429440.p?skuId=6429440")
#
# good
# <button class="btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button" type="button" style="padding:0 8px">
# </button>
# bad
# <button class="btn btn-disabled btn-lg btn-block add-to-cart-button" disabled="" type="button" style="padding: 0px 8px;">Sold Out</button>