This script was developed for use in Arbitration Committee Elections December 2008.
To use it, you must customize your call to main(...) at the bottom, specifying:
Example|- Jimbo Wales|+ Willy on Wheels|-
Code is released under the terms of the MIT license (make sure you understand the "WITHOUT WARRANTY OF ANY KIND" part).
#!/usr/bin/env python
import os, sys, re
sys.path.append(os.environ['HOME']+'/pywikipedia')
import wikipedia
def main(votePrefix, voteFile, voteTexts):
L = open(voteFile,'r').readlines()
L = [l.strip().split('|') for l in L]
site = wikipedia.getSite()
for vote in L:
if vote[1] == '+':
v = True
elif vote[1] == '-':
v = False
else:
continue
votePage = wikipedia.Page(site, votePrefix + '/' + vote[0])
txt = votePage.get()
rx = re.search('^(.*)(\n== *Support *==\n.*[^\n])(\n+== *Oppose *==.*[^\n])(\n*)', txt, re.DOTALL)
if rx:
if v:
newtxt = rx.group(1) + rx.group(2) + '\n# ' + voteTexts[v] + rx.group(3) + rx.group(4)
else:
newtxt = rx.group(1) + rx.group(2) + rx.group(3) + '\n# ' + voteTexts[v] + rx.group(4)
votePage.put(
newtext=newtxt,
comment='Voting '+['oppose','support'][v]+' using [[User:Misza13/Scripts/ace_voter.py|ace_voter.py]].',
watchArticle=v,
minorEdit=False,
force=True)
if __name__ == '__main__':
try:
main(
'Wikipedia:Arbitration Committee Elections December 2008/Vote',
'votes.txt',
["'''[[User:Misza13/ACE 2008|Oppose]]'''. ~~~~","'''[[User:Misza13/ACE 2008|Support]]'''. ~~~~"])
finally:
wikipedia.stopme()