-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathweekly_utils_main.py
48 lines (41 loc) · 1.64 KB
/
weekly_utils_main.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
# weekly is a lie, this runs twice-daily
import datetime
import scrape_runes
from mwrogue.esports_client import EsportsClient
from mwcleric.auth_credentials import AuthCredentials
credentials = AuthCredentials(user_file="me")
site = EsportsClient('lol', credentials=credentials) # Set wiki
now_timestamp = datetime.datetime.utcnow().isoformat()
with open('daily_last_run.txt','r') as f:
last_timestamp = f.read()
with open('daily_last_run.txt','w') as f:
f.write(now_timestamp)
revisions = site.client.api('query', format='json',
list='recentchanges',
rcstart=now_timestamp,
rcend=last_timestamp,
rcprop='title|ids|patrolled',
rclimit='max',
rctoponly=1, # commented bc we need all revisions to patrol user pages
rcdir = 'older'
)
pages_for_runes = []
for revision in revisions['query']['recentchanges']:
title = revision['title']
if title.startswith('Data:'):
if title not in pages_for_runes:
pages_for_runes.append(title)
success_page = site.client.pages['User:RheingoldRiver/Maint Log']
text = success_page.text()
text = text + '\nScript finished maint successfully: ' + now_timestamp
try:
scrape_runes.scrape(site, pages_for_runes, False)
text = text + '\nScript finished regular runes successfully: ' + now_timestamp
except Exception as e:
text = text + '\nException running regular runes: ' + str(e) + ' ' + now_timestamp
try:
scrape_runes.scrapeLPL(site, pages_for_runes, False)
text = text + '\nScript finished everything successfully: ' + now_timestamp
except Exception as e:
text = text + '\nException running LPL runes: ' + str(e) + ' ' + now_timestamp
success_page.save(text,tags='daily_errorfix')