-
Notifications
You must be signed in to change notification settings - Fork 2
/
cleanupbot.py
executable file
·51 lines (36 loc) · 1.37 KB
/
cleanupbot.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
#!/usr/bin/env python3
# -.- encoding: utf-8 -.-
import mwclient
import config
import calendargenerator
import datetime
import pytz
site = mwclient.Site((config.protocol, config.server), path="/mediawiki/")
termine = site.Pages["Termine"]
termine_archiv = site.Pages["Termine/Archiv"]
termine_text = termine.text()
termine_archiv_text = termine_archiv.text()
threshold_date = datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(calendargenerator.tz) - datetime.timedelta(days=config.archive_threshold_days)
new_termine_text, new_termine_archiv_text, n = calendargenerator.move_to_archive(termine_text, termine_archiv_text, threshold_date)
termine_changed = False
archiv_changed = False
if termine_text != new_termine_text:
print("termine changed")
termine_changed = True
if termine_archiv_text != new_termine_archiv_text:
print("archiv changed")
archiv_changed = True
comment = u"Termine cleanup"
if n > 0:
comment = u"%d Termine ins Archiv verschoben" % n
minor_edit = n == 0
if termine_changed or archiv_changed:
print(">", comment)
print("minor:", minor_edit)
if config.write_wiki and (termine_changed or archiv_changed):
if not site.logged_in:
site.login(config.user, config.password)
if termine_changed:
termine.save(new_termine_text, comment, minor=minor_edit)
if archiv_changed:
termine_archiv.save(new_termine_archiv_text, comment, minor=minor_edit)