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:Unver cat creator.py
#!/usr/bin/python # -*- coding: utf-8 -*- """ Script to create the categories of the images """ # # (C) Filnik, 2008 # # Distributed under the terms of the MIT license. # __version__ = '$Id: $' # import wikipedia, time, re # Please follow the right order or all will be messed up, thanks. months_in_various_languages = { 'commons': None, # Use the default ones (english) 'en': [u'January', u'February', u'March', u'April', u'May', u'June', u'August', u'September', u'October', u'November', u'December'], # The italians use the months in lower case. 'it': [u'gennaio', u'febbraio', u'marzo', u'aprile', u'maggio', u'giugno', u'luglio', u'agosto', u'settembre', u'ottobre', u'novembre', u'dicembre'], } cat_of_the_day_name = { 'commons': u'Category:Unknown as of', 'it': u'Categoria:Immagini senza informazioni dal', } cat_of_the_month_name = { 'commons': u'Category:Unknown -', 'it': u'Categoria:Immagini senza informazioni -', } # Data = text in the edit option cat_of_the_day_data = { # Use __month__ and so on instead of the data, it will replaced with the right one. 'commons' : u'{{delete assist}}\n\n[[Category:Unknown - __month__ __year__| __day__]]', 'it': u'[[Categoria:Immagini senza informazioni - __month__ __year__| __day__]]', } cat_of_the_month_data = { 'commons' : u'{{delete assist}}\n{{CategoryTOC}}\n[[Category:Unknown| __year____month_number__]]', 'it' : u'{{subst:Utente:Nikbot/categoria unverified}}\n\n[[Categoria:Immagini senza informazioni| __month_number____year__]]', } summary_of_the_month = { 'commons' : u'Bot: Creating the month category for unknown license', 'en': u'Bot: Creating the month category for unknown license', 'it': u'Bot: Creo la categoria del mese per gli unverified', } summary_of_the_day = { 'commons' : u'Bot: Creating the daily category for unknown license', 'en': u'Bot: Creating the daily category for unknown license', 'it': u'Bot: Creo la categoria del giorno per gli unverified', } def main(): """ Main function """ # Defing the site site = wikipedia.getSite() # Loading the default args arg = wikipedia.handleArgs() # Translating the data above using the right one months = wikipedia.translate(site, months_in_various_languages) if months == None: months = wikipedia.translate(wikipedia.getSite('en', 'wikipedia'), months_in_various_languages) cat_day_name = wikipedia.translate(site, cat_of_the_day_name) cat_month_name = wikipedia.translate(site, cat_of_the_month_name) cat_month_data = wikipedia.translate(site, cat_of_the_month_data) summary_month = wikipedia.translate(site, summary_of_the_month) summary_day = wikipedia.translate(site, summary_of_the_day) cat_day_data_default = wikipedia.translate(site, cat_of_the_day_data) cat_month_data_default = wikipedia.translate(site, cat_of_the_month_data) # Now we have to find out what is yesterday and what is tomorrow # Local time in seconds basing on a selected time (default function) current_time = time.time() # Seconds In A Day siad = 24*60*60 # Getting the current time in a tuple with the day, month, year and so on date = time.localtime(current_time) # Pick up the year year = date[0] # Pick up the month month = months[date[1] - 1] # The first for our list is number "0", # in date list 1, get the right mounth ;-) # Pick up the day day = date[2] # Now just do the same for yesterday one_day_ago_time = time.localtime(current_time - siad) one_day_ago = one_day_ago_time[2] one_day_ago_month = months[one_day_ago_time[1] - 1] one_day_ago_year = one_day_ago_time[0] # And for tomorrow one_day_in_future_time = time.localtime(current_time + siad) one_day_in_future = one_day_in_future_time[2] one_day_in_future_month = months[one_day_in_future_time[1] - 1] one_day_in_future_year = one_day_in_future_time[0] wikipedia.output(u'Checking the categories...') month_checked = False # Checking the three days for time_selected in [(one_day_ago, one_day_ago_month, one_day_ago_year), (day, month, year), (one_day_in_future, one_day_in_future_month, one_day_in_future_year)]: cat_day_data = cat_day_data_default cat_month_data = cat_month_data_default # Check the month if month_checked == False: cat_month_data = re.sub(r'__month__', str(time_selected[1]), re.sub(r'__year__', str(time_selected[2]), cat_month_data)) category_month_name = "%s %s %s" % (cat_month_name, time_selected[1], time_selected[2]) category_month = wikipedia.Page(site, category_month_name) # Category Month Page object if category_month.exists(): wikipedia.output(u'The category of the month exists.') else: wikipedia.output(u"The category of the month doesn't exists. Let's create it.") category_month.put(cat_month_data, summary_month) if one_day_ago_month == month and one_day_in_future_month == month: month_checked = True # Replacing the var used as tag with the right data. cat_day_data = re.sub(r'__day__', str(time_selected[0]), re.sub(r'__month__', str(time_selected[1]), re.sub(r'__year__', str(time_selected[2]), cat_day_data))) print cat_day_data category_day_name = "%s %s %s %s" % (cat_day_name, time_selected[0], time_selected[1], time_selected[2]) category_day = wikipedia.Page(site, category_day_name) # Category Day Page object if category_day.exists(): wikipedia.output(u'The category of the day: %s exists.' % time_selected[0]) else: wikipedia.output(u"The category of the day: %s doesn't exists. Let's create it." % time_selected[0]) category_day.put(cat_day_data, summary_day) wikipedia.output(u'Done, exit.') if __name__ == "__main__": # Use try and finally, to put the wikipedia.stopme() always at the end of the code. try: try: main() except wikipedia.BadTitle: wikipedia.output(u"Wikidown or server's problem. Quit.") wikipedia.stopme() finally: wikipedia.stopme()