Advertisement
Riley_Huntley

RyanBot 3

Apr 28th, 2016
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys, os
  4. print os.environ['HOME']
  5. sys.path.append(os.environ['HOME'] + '/pywikipedia')
  6.  
  7. import wikipedia
  8. import datetime
  9.  
  10. site = wikipedia.getSite('commons','commons')
  11. wikipedia.setAction( "Creating daily maintenance categories." )
  12.  
  13. # define month names to be locale independent
  14. month = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
  15. # list of categories to be created and their content templates
  16. cats = [
  17. { 'page': "Orphaned talk page as of {day} {month} {year}", 'daily': True,
  18. 'template': "{{Delete cat when empty|1={year}{month}{day}}}{{UnknownHeader}}[[Category:Orphaned talk pages| {year}{month}{day}]]" }
  19. ]
  20.  
  21. today = datetime.datetime.today()
  22.  
  23. day = today.day
  24. month = month[today.month-1]
  25. year = today.year
  26. monthnum = "%02d" % today.month
  27.  
  28. for cat in cats :
  29. if not cat['daily'] and day != 1 :
  30. continue
  31.  
  32. catname = cat['page'].format(day=day,month=month,year=year,monthnum=monthnum)
  33. text = cat['template'].format(day=day,month=month,year=year,monthnum=monthnum)
  34.  
  35. page = wikipedia.Page(site, 'Category:' + catname )
  36.  
  37. if not page.exists() :
  38. print "creating [[Category:%s]]." % catname
  39. print text
  40. page.put( text )
  41. </source>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement