-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
57 lines (45 loc) · 1.56 KB
/
scraper.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
from bs4 import BeautifulSoup
import urllib
import datetime
import json
from win11toast import toast
with open('list.txt','r') as f:
vns = f.readlines()
with open('dates.json','r') as f:
dates = json.load(f)
for i in vns:
print("Checking",i)
name = i.lower().strip()
name = name.split(' ')
name = '-'.join(name)
url = f'http://dikgames.com/{name}/'
hdr = {'User-Agent': 'Mozilla/5.0'}
try:
request = urllib.request.Request(url,headers=hdr)
response = urllib.request.urlopen(request)
htmldata = response.read()
soup = BeautifulSoup(htmldata, 'html.parser')
update_date = soup.find_all("span", class_="last-updated")[0].contents[0][14:]
update_date = datetime.datetime.strptime(update_date, '%B %d, %Y').date()
except:
print(f"Couldn't fetch data for {name}")
continue
flag = True
if(name in dates.keys()):
prev_date = datetime.datetime.strptime(dates[name], '%B %d, %Y').date()
if(prev_date==update_date):
flag = False
dates[name]=update_date.strftime('%B %d, %Y')
if(flag):
heading = f'New Update for {i}'
body = f'Updated on {update_date}'
open_link = {'activationType': 'protocol', 'arguments': url, 'content': 'Open Link'}
try:
toast(heading,body,on_click=url,buttons=[open_link,'Dismiss'])
except:
print('-------------------------')
print(heading)
print(body)
print(url)
with open('dates.json','w') as f:
dates = json.dump(dates,f)