-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.pyw
56 lines (50 loc) · 2.34 KB
/
scraper.pyw
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
import os
import time
from bs4 import BeautifulSoup
import requests
import webhook
while (True):
if not os.path.exists("src/urls.txt"):
print("No Urls loaded. Exiting")
exit()
file_object = open('src/urls.txt', 'r')
urls = file_object.readlines()
for i in urls:
page = requests.get(i)
soup = BeautifulSoup(page.content, 'html.parser')
try:
#Get Price
old_price = soup.find('div', attrs={'class':'discount_original_price'})
final_og_price = old_price.text.strip()
new_price = soup.find('div', attrs={'class':'discount_final_price'})
final_new_price = new_price.text.strip()
percent = soup.find('div', attrs={'class':'discount_pct'})
final_percent = percent.text.strip()
name = i.split("/")[5]
#If name contains underscore replace with space
if "_" in name:
name = name.replace("_", " ")
#If file with price does not exist send Message with Discount and write price to file
if not os.path.exists(f"src/{name}.txt"):
with open(f"src/{name}.txt", "w") as file:
file.write(final_new_price)
webhook.sendHook(name, final_og_price, final_new_price, final_percent, i, "Not Found")
#Checks if Discount Price is same or changed
with open(f"src/{name}.txt", "r") as f:
text = f.readlines()
if final_new_price in text:
webhook.sendLog(f"Price for {name} didnt Change")
else:
webhook.sendLog(f"Price for {name} has changed from {text[0]} to {final_new_price}")
webhook.sendHook(name, final_og_price, final_new_price, final_percent, i, text[0])
#Writes current Discount to file
with open(f"src/{name}.txt", "w") as file:
file.write(final_new_price)
except Exception:
normal_price = soup.find('div', attrs={'class':'game_purchase_price price'})
final_price = normal_price.text.strip()
name = i.split("/")[5]
if "_" in name:
name = name.replace("_", " ")
webhook.sendLog(f"No Discount on {name}")
time.sleep(60 * 60)