-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSneakerNotifier.py
132 lines (115 loc) · 5.59 KB
/
SneakerNotifier.py
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
# -selenium webdriver-
from logging import fatal
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
# config file import
import config
import requests # for discord webhook
# makes the bot only use the specified cores. (logical processors)
#import psutil
#p = psutil.Process()
# p.cpu_affinity([2,3,5,6,7,9,10,11,12,13,14])
# get the webdriver you want to use.
browser = webdriver.Firefox(executable_path=r'.\webdrivers\geckodriver.exe')
browser.get(config.PageURL)
#wait = WebDriverWait(browser, 2)
print('waiting')
element = WebDriverWait(browser, 20).until(lambda x: x.find_element_by_xpath(config.Size_Xpath)) # waits for page to finish loading
print('finished waiting')
# timestamp of when the bot was started
print('Time started =', config.current_time)
print('--------------------------------------')
SizeAvailable = browser.find_element_by_xpath(config.Size_Xpath).get_attribute('data-qa')
ShoeNamePrimary = browser.find_element_by_xpath('//*[@id="root"]/div/div/div[1]/div/div[1]/div[2]/div/section[1]/div[2]/aside/div/div[1]/h1').get_attribute('innerHTML')
ShoeNameSecondary = browser.find_element_by_xpath('//*[@id="root"]/div/div/div[1]/div/div[1]/div[2]/div/section[1]/div[2]/aside/div/div[1]/h5').get_attribute('innerHTML')
ShoeThumbnail = browser.find_element_by_xpath('/html/body/div[2]/div/div/div[1]/div/div[1]/div[2]/div/section[1]/div[1]/div/div[6]/figure/img').get_attribute('src')
#all_children_by_xpath = browser.find_elements_by_xpath(f'{config.Size_Xpath}.//*')
#print(all_children_by_xpath)
parentElement = browser.find_element_by_xpath(config.Size_Xpath)
elementList = parentElement.find_elements_by_tag_name('button')
print('===============')
print(parentElement)
print(elementList)
print('===============')
print(ShoeNamePrimary)
print(ShoeNameSecondary)
print(SizeAvailable)
# ~~ debug ~~
if config.DebugMode == True:
print('debug value is true.')
print('~~~~~~~~~~~~~~~~~~~~~~~~')
print(f'*Debug Info*\nAutoBuy = {config.AutoBuy}\nAutoCart = {config.AutoCart}\nWinToast = {config.WindowsToasts}\nTestMode = {config.TestMode}')
print('--------------------------------------')
# check if {InStockColor} is the same as the {SizeBgColor}
if SizeAvailable == 'size-unavailable': # size is unavailable
print('out of stock')
# browser.refresh()
elif SizeAvailable != 'size-unavailable': # size is available
print('in stock')
# notification settings (you can change them in the config)
if config.WindowsToasts == True:
from logging import debug
from win10toast import ToastNotifier
toaster = ToastNotifier()
toaster.show_toast(f'Sneaker Bot v{config.SneakerBotVersion}',
(f'{ShoeNamePrimary} are in stock'),
icon_path='assets\\sneakerbot-icon.ico',
duration=999999,
threaded=True)
if config.DiscordWebhooks == True:
url = config.DiscordWebhookURL
if config.DebugMode == True:
embed = {
'title': 'Sneakers in stock!',
'color': 15052624, # 15052624 orange, 14708343 bright red, 12017246 darker red
'thumbnail': {
'url': ShoeThumbnail
},
'fields': [
{
'name': (f'{ShoeNamePrimary} - {ShoeNameSecondary}'),
'value': (f'[store link]({config.PageURL})\n▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬\n```▬ Debug Info ▬\nAutoBuy = {config.AutoBuy}\nAutoCart = {config.AutoCart}\nDiscordHook = {config.DiscordWebhooks}\nWinToast = {config.WindowsToasts}\nTestMode = {config.TestMode}\n```')
}
],
'footer': {
'text': (f'Made by MBlais.dev • {config.current_time} • SneakerBot v{config.SneakerBotVersion}'),
'icon_url': 'https://i.imgur.com/MbrG9HM.png'
}
}
elif config.DebugMode == False:
embed = {
'title': 'Sneakers in stock!',
'color': 5546086, # dark green:5546086, light green:8776060
'thumbnail': {
'url': ShoeThumbnail
},
'fields': [
{
'name': (f'{ShoeNamePrimary} - {ShoeNameSecondary}'),
'value': (f'[store link]({config.PageURL})\n▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬')
}
],
'footer': {
'text': (f'Made by MBlais.dev • {config.current_time} • SneakerBot v{config.SneakerBotVersion}'),
'icon_url': 'https://i.imgur.com/MbrG9HM.png'
}
}
data = {
'username': (f'SneakerBot v{config.SneakerBotVersion}'),
'avatar_url': 'https://i.imgur.com/eVDSFTr.png',
'embeds': [
embed
],
}
headers = {
'Content-Type': 'application/json'
}
result = requests.post(url, json=data, headers=headers)
if 200 <= result.status_code < 300:
print(f'Webhook sent {result.status_code}')
else:
print(f'Not sent with {result.status_code}, response:\n{result.json()}')