-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIMR&Database.py
More file actions
105 lines (77 loc) · 3.09 KB
/
IMR&Database.py
File metadata and controls
105 lines (77 loc) · 3.09 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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import win32api, win32con
import requests
import time
#discord requests setup
# alt authorization
#NDQ1NzE0Njc2OTQ1Mzg3NTIw.YcE4Mg.TMfuQyq7Kk-C4CTE464-49RUp6E
# main authorization
#MzMzOTUxMDIzOTQ3MzE3MjQ4.YcEykA.SmTXlNrEK7e8yM9MAE8b9ZE7tE4"
header = {
'authorization' : "NDQ1NzE0Njc2OTQ1Mzg3NTIw.YcE4Mg.TMfuQyq7Kk-C4CTE464-49RUp6E"
}
#database setup
#key changes per program instance
brandkey = "IMR"
#arraylist declarations
links = []
stockIDs = []
#reads and interprets gunpowder database
with open(r'C:\Users\bento\Desktop\The Project\Database.txt') as f:
lines = f.readlines()
for x in lines:
if brandkey not in x:
continue
else:
links.append(x[x.find('http') : x.find("\t", x.find('http'))])
stockIDs.append(x[x.find("\t", x.find('http')) + 1 : x.find("\n")])
print(lines)
print(stockIDs)
#selenium setup
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get('https://shop.hodgdon.com/' + brandkey.lower())
#main loop
time_counter = 0
while(True):
elements = []
for l in range(0, len(stockIDs)):
for x in range(1, 47):
article = WebDriverWait(driver, 100).until(
EC.presence_of_element_located((By.XPATH, '/html/body/div[2]/div/main/section/div/article/div/section/div/div[2]/div/div[2]/div/div[' + str(x) + ']/article'))
)
entity_id = article.get_attribute("data-entity-id")
if entity_id == stockIDs[l]:
elements.append(article)
for x in range(0, len(elements)):
article_class = elements[x].get_attribute("class")
if "out-of-stock" not in article_class:
payload = {
'content' : links[x]
}
r = requests.post("https://discord.com/api/v9/channels/922667219756920843/messages", data=payload, headers=header)
else:
continue
for x in range(1, 6):
time.sleep(1)
time_counter += 1
if(time_counter % 900 == 0):
payload = {
'content' : str(time_counter/60) + " minutes have elapsed"
}
r = requests.post("https://discord.com/api/v9/channels/922879447227572274/messages", data=payload, headers=header)
#driver.refresh()
# varget = WebDriverWait(driver, 100).until(
# EC.presence_of_element_located((By.XPATH, '/html/body/div[2]/div/main/section/div/article/div/section/div/div[2]/div/div[2]/div/div[34]/article'))
# )
# varget = driver.find_element_by_xpath('/html/body/div[2]/div/main/section/div/article/div/section/div/div[2]/div/div[2]/div/div[34]/article')
# varget_stock = varget.get_attribute("class")
# varget store page element link
# /html/body/div[2]/div/main/section/div/article/div/section/div/div[2]/div/div[2]/div/div[34]/article
# varget out of stock buy link xpath
# /html/body/div[2]/div/main/section/div/article/div/section/div/div[2]/div/div[2]/div/div[39]/article/div/div/div/article/div[1]/div[2]/a[1]
# varget in stock buy link xpath
# /html/body/div[2]/div/main/section/div/article/div/section/div/div[2]/div/div[2]/div/div[39]/article/div/div/div/article/div[1]/div[2]/a[2]