Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | None | 0 0
  1. import mwclient
  2. import datetime
  3.  
  4. site='asdfasdfasdf.org'
  5. path="/w/"
  6. user="asdfasdfasdf"
  7. password="asdfasdfasdfasdfasdf"
  8. logname="asdfasdfasdfasdfasdf" # hi there.
  9.  
  10. months=["January","February","March","April","May","June","July","August","September","October","November","December"]
  11.  
  12. def log(message,author):
  13.     global site, path, user, password, logname #Temporary fix for debugging
  14.     site=mwclient.Site(site, path=path)
  15.     site.login(user,password)
  16.     page=site.Pages[logname]
  17.     text=page.edit()
  18.     lines=text.split('\n')
  19.     position=0
  20.     # Try extracting latest date header
  21.     for line in lines:
  22.         position+=1
  23.         if line.startswith("=="):
  24.             undef,month,day,undef=line.split(" ",3)
  25.             break
  26.  
  27.     # Um, check the date
  28.     now=datetime.datetime.utcnow()
  29.     logline="* %02d:%02d %s: %s" % ( now.hour, now.minute, author, message )
  30.     if months[now.month-1]!=month or now.day!=int(day):
  31.         lines.insert(0,"")
  32.         lines.insert(0,logline)
  33.         lines.insert(0,"== %s %d =="%(months[now.month-1],now.day))
  34.     else:
  35.         lines.insert(position,logline)
  36.     page.save('\n'.join(lines),"%s (%s)"%(message,author))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement