Revision: 5831 Author: multichill Date: 2008-08-21 20:52:15 +0000 (Thu, 21 Aug 2008)
Log Message: ----------- Added cooldown period.
We want to wait several days after the last edit before we start moving things around. This it to prevent edit wars and vandals.
Modified Paths: -------------- trunk/pywikipedia/category_redirect.py
Modified: trunk/pywikipedia/category_redirect.py =================================================================== --- trunk/pywikipedia/category_redirect.py 2008-08-21 19:49:47 UTC (rev 5830) +++ trunk/pywikipedia/category_redirect.py 2008-08-21 20:52:15 UTC (rev 5831) @@ -15,10 +15,14 @@
import wikipedia, config, catlib from category import * +from datetime import datetime +from datetime import timedelta
redirect_templates = [u'Category redirect', u'Categoryredirect', u'See cat', u'Seecat', u'Catredirect', u'Cat redirect', u'CatRed', u'Catredir'] move_message = u'Moving from [[%s|%s]] to [[%s|%s]] (following [[Template:Category redirect|category redirect]])' +cooldown = 7 # days
+ def get_redirect_cat(category=None): ''' Return the target category @@ -33,6 +37,15 @@ return None return destination
+def readyToEdit(old_category): + ''' + If the category is edited more recenty than cooldown, return false, otherwise true. + ''' + dateformat ="%Y%m%d%H%M%S" + today = datetime.now() + deadline = today + timedelta(days=-cooldown) + old_category.get() + return (deadline.strftime(dateformat) > old_category.editTime())
def main(): ''' @@ -45,24 +58,27 @@ catbot = None
for old_category in dirtycat.subcategories(): - destination = get_redirect_cat(old_category) - if destination: - wikipedia.output(destination.title()) - for page in old_category.articles(): - try: - catlib.change_category(page, old_category, destination, move_message % (old_category.title(), old_category.titleWithoutNamespace(), destination.title(), destination.titleWithoutNamespace())) - except wikipedia.IsRedirectPage: - wikipedia.output(page.title() + u' is a redirect!') - for cat in old_category.subcategories(): - try: - catlib.change_category(cat, old_category, destination, move_message % (old_category.title(), old_category.titleWithoutNamespace(), destination.title(), destination.titleWithoutNamespace())) - except wikipedia.IsRedirectPage: - wikipedia.output(page.title() + u' is a redirect!') - #Dummy edit to refresh the page, shouldnt show up in any logs. - try: - old_category.put(old_category.get()) - except: - wikipedia.output(u'Dummy edit at ' + old_category.title() + u' failed') + #We want to wait several days after the last edit before we start moving things around. + #This it to prevent edit wars and vandals. + if(readyToEdit(old_category)): + destination = get_redirect_cat(old_category) + if destination: + wikipedia.output(destination.title()) + for page in old_category.articles(): + try: + catlib.change_category(page, old_category, destination, move_message % (old_category.title(), old_category.titleWithoutNamespace(), destination.title(), destination.titleWithoutNamespace())) + except wikipedia.IsRedirectPage: + wikipedia.output(page.title() + u' is a redirect!') + for cat in old_category.subcategories(): + try: + catlib.change_category(cat, old_category, destination, move_message % (old_category.title(), old_category.titleWithoutNamespace(), destination.title(), destination.titleWithoutNamespace())) + except wikipedia.IsRedirectPage: + wikipedia.output(page.title() + u' is a redirect!') + #Dummy edit to refresh the page, shouldnt show up in any logs. + try: + old_category.put(old_category.get()) + except: + wikipedia.output(u'Dummy edit at ' + old_category.title() + u' failed')
if __name__ == "__main__": try:
pywikipedia-l@lists.wikimedia.org