Advertisement
Guest User

Untitled

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