Revision
3 -
Fri Apr 25 03:24:18 2008 UTC
(2 years, 4 months ago)
by
dantman
File size: 4256 byte(s)
Checking in my assortment of half-baked, defunct, and obsolete bot scripts... heh
batchcmd.py - A script to run a series of commands on a wiki.
GaiaitemBot.py - An old script for the Gaiapedia to create item pages (Defunct)
GaiaplotBot.py - Plotwiki/Gaiapeida syncing (Defunct)
GE-AutoTemplate-Bot.py - ACG Bot for syncing templates (Obsolete)
GE-CleanDelete-Bot.py - ACG Bot for cleaning out deleted sync pages. (Half-Baked)
GE-ExportImport-Bot.py - ACG Bot for importing Wikipedia pages into a Wikia ACG wiki and tweaking them to fit (Half-Baked, Defunct)
GE-ImageMirror-Bot.py - ACG Bot for syncing images (Defunct)
GE-MessageBot-Bot.py - ACG Bot for syncing messages (Half-Baked)
GE-Style-Bot.py - ACG Bot for syncing... Erm, stylesheets? heh... no clue (Half-Baked, Defunct)
GE-TagSync-Bot.py - ACG Bot for syncing pages tagged with TagSync. (Actively used, however it's missing some functionality I want for it) (Depends on GESync.py)
GE-UserBox-Bot.py - ACG Bot for syncing UserBoxes (Unknown... Perhaps Defunct, planned to be Obsolete)
GESync.py - Class for ACG Sync bots to use common code from.
Naruto-JutsuFormat-Bot.py - Narutopedia bot for formatting of the [[List of (Nin|Gen|Tai)jutsu]] pages (Defunct)
scarteleu-earthenringeu-copy.py - Old bot for when earthenringeu wanted me to clone content from scarteleu for them.
1 # -*- coding: utf-8 -*-
2 """
3 This bot is used by the Wikia Graphical Entertainment Project to keep templates standard across the wikia in the project.
4 Info: http://en.anime.wikia.com/wiki/Project:Bots/AutoTemplate
5 """
6
7 import sys, re
8 import wikipedia, pagegenerators, catlib, config
9
10 msg = {
11 'en':u'[[Anime:Project:Bots/AutoTemplate|AutoTemplateBot]].',
12 }
13
14 def main():
15 #Setup Familys for Wikia Involved
16 anime = wikipedia.getSite(code=u'en', fam=u'anime')
17 wikipedia.setAction(wikipedia.translate(anime, msg))
18 siteList = []
19 templateList = []
20
21 #Get Project Wiki Listing
22 wikiaIds = []
23 page = wikipedia.Page(anime, u'Bots/Wiki', None, 4)#4=Project Namespace
24 try:
25 text = page.get()
26 r = re.compile(u'^.*<!-- \|\|START\|\| -->\n?', re.UNICODE | re.DOTALL)
27 text = re.sub(r, u'', text)
28 r = re.compile(u'\n?<!-- \|\|END\|\| -->.*$', re.UNICODE | re.DOTALL)
29 text = re.sub(r, u'', text)
30 r = re.compile(u'\n', re.UNICODE | re.MULTILINE | re.DOTALL)
31 wikilist = re.split(r, text)
32 r = re.compile(u'^#|^\s*$|^\[', re.UNICODE | re.MULTILINE | re.DOTALL)
33 for wiki in wikilist:
34 if not re.match(r, wiki):
35 wikiaIds.append(wiki)
36 except wikipedia.NoPage:
37 return False
38
39
40 for wiki in wikiaIds:
41 siteList.append(wikipedia.getSite(code=u'en', fam=wiki))
42
43 #Get Template List
44 page = wikipedia.Page(anime, u'Bots/AutoTemplate/Templates', None, 4)#4=Project Namespace
45 try:
46 text = page.get()
47 r = re.compile(u'^.*<!-- \|\|START\|\| -->\n?', re.UNICODE | re.DOTALL)
48 text = re.sub(r, u'', text)
49 r = re.compile(u'\n?<!-- \|\|END\|\| -->.*$', re.UNICODE | re.DOTALL)
50 text = re.sub(r, u'', text)
51 r = re.compile(u'\n', re.UNICODE | re.MULTILINE | re.DOTALL)
52 templates = re.split(r, text)
53 r = re.compile(u'^#|^\s*$', re.UNICODE | re.MULTILINE | re.DOTALL)
54 for template in templates:
55 if not re.match(r, template ):
56 templateList.append(template)
57 except wikipedia.NoPage:
58 return False
59
60 #Mirror the Templates category and all subcategorys to all the wiki.
61 TemplateCategorys = []
62 cat = catlib.Category(anime, u'Category:Templates')
63 TemplateCategorys.append(cat)
64
65 catlist = cat.subcategories(True)
66
67 starts = re.compile(u'^Category:Templates', re.UNICODE | re.DOTALL)
68 for category in catlist:
69 if re.match(starts, category.title()):
70 TemplateCategorys.append(category)
71
72 for category in TemplateCategorys:
73 categorySource = u'{{networkMirror|%s|anime|category}}\n%s' % (category.title(),category.get())
74
75 if categorySource != u'':
76 for site in siteList:
77 siteCategory = catlib.Category(site, category.title())
78 siteSource = u''
79 try:
80 siteSource = siteCategory.get()
81 except wikipedia.NoPage:
82 wikipedia.output(u'Site %s has no %s category, creating it' % (site, category.title()))
83 if siteSource != categorySource:
84 wikipedia.output(u'Site \'%s\' category status: Needs Updating' % site)
85 wikipedia.output(u'Updating category on %s' % site)
86 siteCategory.put(categorySource)
87 else:
88 wikipedia.output(u'Site \'%s\' category status: Ok' % site)
89 else:
90 wikipedia.output(u'Category %s is blank, skipping category' % category.title())
91
92 for template in templateList:
93 wikipedia.output(u'Doing Template %s' % template)
94 templatePage = wikipedia.Page(anime, template, None, 10)#10=Template Namespace
95 templateSource = u''
96 if template == u'AutoTemplate':
97 templateSource = templatePage.get()
98 else:
99 templateSource = u'<noinclude>{{AutoTemplate}}\n</noinclude>%s' % templatePage.get()
100
101 if templateSource != u'':
102 for site in siteList:
103 sitePage = wikipedia.Page(site, template, None, 10)#10=Template Namespace
104 siteSource = u''
105 try:
106 siteSource = sitePage.get()
107 except wikipedia.NoPage:
108 wikipedia.output(u'Site %s has no %s template, creating it' % (site, template))
109 if siteSource != templateSource:
110 wikipedia.output(u'Site \'%s\' template status: Needs Updating' % site)
111 wikipedia.output(u'Updating template on %s' % site)
112 sitePage.put(templateSource)
113 else:
114 wikipedia.output(u'Site \'%s\' template status: Ok' % site)
115 else:
116 wikipedia.output(u'Template %s is blank, skipping template' % template)
117
118
119 if __name__ == "__main__":
120 try:
121 main()
122 finally:
123 wikipedia.stopme()