-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathninupdates-check.py
More file actions
88 lines (71 loc) · 3.31 KB
/
Copy pathninupdates-check.py
File metadata and controls
88 lines (71 loc) · 3.31 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
#!/usr/bin/env python3
import configparser
import json
import os
import requests
import time
from urllib.parse import urlparse, parse_qs
from apscheduler.schedulers.blocking import BlockingScheduler
import feedparser
import sys
import pprint
os.makedirs('systems', exist_ok=True)
sched = BlockingScheduler()
print('Starting ninupdates-check')
@sched.scheduled_job('cron', minute='5,35', second=30)
def check_ninupdates():
print('Running a check')
config = configparser.ConfigParser()
config.read('config.ini')
# ugly but it works
ninupdates_feed = feedparser.parse('https://yls8.mtheall.com/ninupdates/feed.php')
# ninupdates_feed = feedparser.parse(sys.argv[1])
reported_systems = []
for entry in ninupdates_feed['entries']:
system, ver = entry['title'].rsplit(maxsplit=1)
if system in reported_systems:
continue
reported_systems.append(system)
reporturl = entry['link']
# pprint.pprint(entry)
reporturl_date = parse_qs(urlparse(reporturl).query)['date'][0]
reportpath = 'systems/{}.json'.format(system)
to_write = {'reportdate': reporturl_date}
if not os.path.isfile(reportpath):
to_write['ver'] = ver
with open(reportpath, 'w') as f:
json.dump(to_write, f)
else:
message = ''
with open(reportpath, 'r') as f:
oldver = json.load(f)
if oldver['reportdate'] != reporturl_date:
print('reportdate:', oldver['reportdate'])
print('reporturl_date:', reporturl_date)
# "Reminder to not update until confirmed safe or known broken features are fixed."
if reporturl_date == ver:
message = '\N{BLACK DOWN-POINTING DOUBLE TRIANGLE} System updated detected for {}: **[{}]({})**'.format(system, reporturl_date, reporturl)
to_write['ver'] = reporturl_date
else:
message = '\N{BLACK DOWN-POINTING DOUBLE TRIANGLE} System updated detected for {}: **[{}]({})**'.format(system, ver, reporturl)
to_write['ver'] = ver
with open(reportpath, 'w') as f:
json.dump(to_write, f)
elif oldver['reportdate'] == oldver['ver'] and len(ver) not in {19, 17}:
print('reportdate:', oldver['reportdate'])
print('ver:', ver)
# lazy method of seeing if an update + vernumber was found before the bot caught the update in the first place
message = '\N{INFORMATION SOURCE} New update version for {}: **[{}]({})**'.format(system, ver, reporturl_date)
to_write['ver'] = ver
with open(reportpath, 'w') as f:
json.dump(to_write, f)
if message:
for server, opts in config.items():
if server != 'DEFAULT':
systems = opts['systems'].split()
if '*' in systems or system in systems:
print('Posting update info for {} to {}'.format(system, server))
r = requests.post(opts['webhook_url'], data={'content': message}) # , 'username': 'Nintendo Updates ({})'.format(server)[0:32]})
print('Done')
sched.start()
# check_ninupdates()