Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.
UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.
Python:Pagemaker.py
# -*- coding: iso-8859-1 -*- # # (C) Filnik it.wikipedia. # # pagemaker.py 1.5 # import wikipedia docstring = \ """ Readme: This Bot generates pages that have at the end the day.month.year. Parameters: -year: to chose the year :-) (default:2007) -month: to chose the month (write it in number, that means that January => 1, Febraury => 2, ecc) (default: January) -directory: to chose the directory before the date (default: UnNews:Aktuelle Nachrichten/) N.B: If the name has spaces between the differents words you have to replace spaces with "_" :-) how in the example -direct: to change the direct variable -readme: The Bot will print this readme :-) Example: python pages.py -directory:Hello_world/ python pages.py -month:3 -year:2008 Note for programmers: I've called some variables with italian names like Gennaio that means January :-) and like numero that means number :) I've also not commented too much the script because i don't think that someone would like to modify that script :-D and the code isn't so difficult :) Some important variable: * wikipedia.setAction() define the object whe you save the page * newtext = text that you'll add everytime you start the bot :) Little Bug: I've fixed a Bug, so if it is 2008, febraury will have 29 days :) It will work correctly untill 2052 :-D So, if this script will be used untill 2052, it will have a little Bug :-D """ # Defing general variables wikipedia.setAction("UnNews Update, kontaktiere [[Benutzer:Tomsen|Tomsen]] wenn der Bot Fehler macht!") (x, year) = (0, '2007') directory = "UnNews:Aktuelle Nachrichten/" direct = "UnNews:" s = 0 # Defining the parameters for arg in wikipedia.handleArgs(): if arg.startswith('-month'): if len(arg) == 7: x = int(wikipedia.input(u'Choose the month :-) (from 1 to 12)')) - 1 else: x = int(arg[7:]) - 1 elif arg.startswith('-year'): if len(arg) == 5: year = wikipedia.input(u'I need to know what year do you want that the pages will have...') else: year = arg[6:] elif arg.startswith('-directory'): if len(arg) == 10: directory = str(wikipedia.input(u"How must begin the pages that you need to create?")) else: directory = str(arg[11:]) elif arg.startswith('-direct'): if len(arg) == 8: direct = str(wikipedia.input(u"How must begin the pages that you need to create?")) else: direct = str(arg[9:]) elif arg == '-readme': print docstring break # Months are from 1 to 12 (January to December) mesi = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"] # The days of a month are from 1 to 30 month1 = range(1,31) # Or from 1 to 31 month2 = range (1, 32) gennaio = month2 # But february is from 1 to 28 febbraio = range(1,29) # But, february can also be from 1 to 29 :-) bisestile = ('2004', '2008', '2012', '2016', '2020', '2024', '2028', '2032', '2036', '2040', '2044', '2048', '2052') for word in bisestile: if word in year: febbraio = range(1,30) # I define the other months marzo = month2 aprile = month1 maggio = month2 giugno = month1 luglio = month2 agosto = month2 settembre = month1 ottobre = month2 novembre = month1 dicembre = month2 def addpage(page, newtext): p = wikipedia.Page(wikipedia.getSite(), page) k = True while k == True: try: p.get() except wikipedia.NoPage: print "Ok, the page doens't exists" p.put(newtext) k = False continue print "The page already exists" k = False continue def todo(): # The list of months me = [gennaio, febbraio, marzo, aprile, maggio, giugno, luglio, agosto, settembre, ottobre, novembre, dicembre] try: numero = me[x] # I prevent that the user choose a wrong month except IndexError: print "\n --> You have choosen a wrong month, please retry. <--" exit() while 1: if int(numero[s]) >= 5: n1 = str(numero[s]) + "." + str(mesi[x]) +"." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year n4 = str(int(numero[s])-3) + "." + str(mesi[x]) + "." + year n5 = str(int(numero[s])-4) + "." + str(mesi[x]) + "." + year elif int(numero[s]) == 4: if int(mesi[x]) != 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year n4 = str(int(numero[s])-3) + "." + str(mesi[x]) + "." + year q = x - 1 numero = me[q] u = s - 1 n5 = str(numero[u]) + "." + "0" + str(int(mesi[x])-1) + "." + year numero = me[x] elif int(mesi[x]) == 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year n4 = str(int(numero[s])-3) + "." + str(mesi[x]) + "." + year n5 = "31.12" + "." + str(int(year)-1) elif int(numero[s]) == 3: if int(mesi[x]) != 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year q = x - 1 numero = me[q] u = s - 1 n4 = str(numero[u]) + "." + "0" + str(int(mesi[x])-1) + "." + year u2 = s - 2 n5 = str(numero[u2]) + "." + "0" + str(int(mesi[x])-1) + "." + year numero = me[x] elif int(mesi[x]) == 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year n4 = "31.12" + "." + str(int(year)-1) n5 = "30.12" + "." + str(int(year)-1) elif int(numero[s]) == 2: if int(mesi[x]) != 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year q = x - 1 numero = me[q] u = s - 1 n3 = str(numero[u]) + "." + "0" + str(int(mesi[x])-1) + "." + year u2 = s - 2 n4 = str(numero[u2]) + "." + "0" + str(int(mesi[x])-1) + "." + year u2 = s - 3 n5 = str(numero[u2]) + "." + "0" + str(int(mesi[x])-1) + "." + year numero = me[x] elif int(mesi[x]) == 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year n4 = "31.12" + "." + str(int(year)-1) n5 = "30.12" + "." + str(int(year)-1) elif int(numero[s]) == 1: if int(mesi[x]) != 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year q = x - 1 numero = me[q] u = s - 1 n2 = str(numero[u]) + "." + "0" + str(int(mesi[x])-1) + "." + year u2 = s - 2 n3 = str(numero[u2]) + "." + "0" + str(int(mesi[x])-1) + "." + year u2 = s - 3 n4 = str(numero[u2]) + "." + "0" + str(int(mesi[x])-1) + "." + year u2 = s - 4 n5 = str(numero[u2]) + "." + "0" + str(int(mesi[x])-1) + "." + year numero = me[x] elif int(mesi[x]) == 1: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year n4 = "31.12" + "." + str(int(year)-1) n5 = "30.12" + "." + str(int(year)-1) else: n1 = str(numero[s]) + "." + str(mesi[x]) + "." + year n2 = str(int(numero[s])-1) + "." + str(mesi[x]) + "." + year n3 = str(int(numero[s])-2) + "." + str(mesi[x]) + "." + year n4 = str(int(numero[s])-3) + "." + str(mesi[x]) + "." + year n5 = str(int(numero[s])-4) + "." + str(mesi[x]) + "." + year newtext1 = "===[[UnNews:" + n1 + "|" + n1 + "]]===\n{{UnNews:" + n1 + "}}\n\n===[[UnNews:" +n2 + "|" + n2 + "]]===\n{{UnNews:" + n2 + "}}\n\n" newtext2 = "===[[UnNews:" + n3 + "|" + n3 + "]]===\n{{UnNews:" + n3 + "}}\n\n===[[UnNews:" +n4 + "|" + n4 + "]]===\n{{UnNews:" + n4 + "}}\n\n" newtext3 = "===[[UnNews:" + n5 + "|" + n5 + "]]===\n{{UnNews:" + n5 + "}}\n\n" newtext = newtext1 + newtext2 + newtext3 + "__NOTOC____NOEDITSECTION__" anothernewtext = "<DynamicPageList>\nnamespace=UnNews\ncategory=" + n1 + "\nnotcategory=nopublish\nshownamespace=false\nmode=unordered\nsuppresserrors=true\n</DynamicPageList>" try: # I define the name of the final page page = directory + n1 page2 = direct + n1 addpage(page, newtext) addpage(page2, anothernewtext) del numero[s] continue except IndexError: print "Stop!" break todo()