#coding: utf-8
"""
This python script, based on pagefromfile.py, is to be used by bots loading batches of words into Wiktionary.
*** This version (io.py} creates plural forms of Ido nouns from a file (io.txt).
"""
#
# (C) Andre Engels, 2004
#
# Distributed under the terms of the MIT license.
#
__version__='$Id: Exp $'
import wikipedia, config
import re, sys, codecs
msg={
'en': u'Mass creating Ido verb forms'
}
starttext = "{{-start-}}"
endtext = "{{-stop-}}"
filename = "io.txt"
include = False
titlestart = u"<<<"
titleend = u">>>"
search_string = u""
force = False
append = "False"
notitle = True
def findpage(t):
search_string = titlestart + "(.*?)" + titleend
try:
location = re.search(starttext+"(*?)"+endtext,t)
if include:
contents = location.group()
else:
contents = location.group(1)
except AttributeError:
print 'Start or end marker not found.'
return
try:
title = re.search(search_string, contents).group(1)
except AttributeError:
wikipedia.output(u"No title found - skipping a page.")
return
else:
page = wikipedia.Page(mysite, title)
wikipedia.output(page.title())
if notitle:
#Remove title (to allow creation of redirects)
contents = re.sub(search_string, "", contents)
#Remove trailing newlines (cause troubles when creating redirects)
contents = re.sub('^*','',contents)
if page.exists():
old_text = page.get()
if not re.search(r'==\s*Ido\s*==', old_text):
contents = old_text + '\n\n----\n' + contents + '\n{{rfc-auto}}\n'
commenttext_add = commenttext + " - appended"
wikipedia.output(u"Page %s already exists, adding to entry!"%title)
page.put(contents, comment = commenttext_add, minorEdit = False)
else:
wikipedia.output(u"Page %s already exists with Ido section, not adding!"%title)
else:
page.put(contents, comment = commenttext, minorEdit = True) # was False (see above)
findpage(t)
return
def main():
text =
f = codecs.open(filename,'r', encoding = config.textfile_encoding)
text = f.read()
findpage(text)
mysite = wikipedia.getSite()
commenttext = wikipedia.translate(mysite,msg)
for arg in sys.argv:
arg = wikipedia.argHandler(arg, 'pagefromfile')
if arg:
if arg.startswith("-start:"):
starttext=arg
elif arg.startswith("-end:"):
endtext=arg
elif arg.startswith("-file:"):
filename=arg
elif arg=="-include":
include = True
#elif arg=="-exclude":
#exclude = True
elif arg=="-appendtop":
append = "Top"
elif arg=="-appendbottom":
append = "Bottom"
elif arg=="-force":
force=True
elif arg=="-safe":
force=False
append="False"
elif arg=='-notitle':
notitle=True
elif arg.startswith("-titlestart:"):
titlestart=arg
elif arg.startswith("-titleend:"):
titleend=arg
elif arg.startswith("-summary:"):
commenttext=arg
else:
wikipedia.output(u"Disregarding unknown argument %s."%arg)
try:
main()
except:
wikipedia.stopme()
raise
else:
wikipedia.stopme()