forked from dantman/pywikia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GaiaplotBot.py
72 lines (57 loc) · 1.79 KB
/
GaiaplotBot.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""
This bot is used by the Gaiapedia/Plotwiki network to update the current events list on Gaiapedia with page links on Plotwiki.
"""
import sys, sre, re
import wikipedia, pagegenerators, catlib, config
msg = {
'en':u'GaiaplotBot current events update.',
}
def main():
gaia = wikipedia.getSite(code=u'en', fam=u'gaia')
plot = wikipedia.getSite(code=u'en', fam=u'plotwiki')
wikipedia.setAction(wikipedia.translate(gaia, msg))
wikipedia.setAction(wikipedia.translate(plot, msg))
final = u'<noinclude><!-- Do not edit this page, this page is automatically created by a Bot. -->\n'
final+= u'==Most Recent Events==</noinclude>\n'
nonrecent = u'<noinclude>==Older Events==\n'
end = u'\n\'\'View everything here on the [[Plotwiki:|plotwiki...]]\'\'</noinclude>'
moreYears = True
year = 04
events = []
temp = []
while moreYears:
y = str(year)
page = wikipedia.Page(plot, u'Template:Pnav%s' % y.zfill(2))
try:
text = page.get()
r = sre.compile(u'^.*<span style=".*normal.*">(.*)</span>.*$', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
text = sre.sub(r, u'\\1', text)
r = sre.compile(u'\s+\|\s+', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
pages = sre.split(r, text)
r = sre.compile(u'\[\[([^|]*)(\|.*)?\]\]', sre.UNICODE)
for p in pages:
temp.append(sre.sub(r, u'\\1', p))
year+=1
except wikipedia.NoPage:
moreYears = False
for e in temp:
if not e in events:
events.append(e)
events = reversed(list(events));
x = 1
for e in events:
final+=u'* [[Plotwiki:%s|]]\n' % e
x+=1
if x==6:
final+=nonrecent
if x<=6:
final+=end
final+=end
page = wikipedia.Page(gaia, u'Plotwiki Current Events')
page.put(final)
if __name__ == "__main__":
try:
main()
finally:
wikipedia.stopme()