Advertisement
Guest User

Me Monday Poster

a guest
Aug 19th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # Reddit 'Me Monday' poster.
  4. # by svkampen, 2012.
  5.  
  6. import reddit # This is a pypi package; installable via easy_install reddit or pip install reddit -U
  7. import time
  8.  
  9. class MeMondayPoster():
  10.     def __init__(self):
  11.         self.reddit = reddit.Reddit(user_agent='me_monday_poster')
  12.         # This is not a real user, ofcourse.
  13.         self.username = 'memondaybot'
  14.         self.password = 'i_post_me_mondays'
  15.         self.reddit.login(self.username, self.password)
  16.         self.startTimer()
  17.  
  18.     def startTimer(self):
  19.         # This will probably take up your CPU; I am not sure how to fix.. (I know quite a bit
  20.         # of Python but preserving CPU: not really) Right now as a fix I have added a time.sleep for every
  21.         # loop to limit cpu usage. I mean, does it really matter if the post arrives one second later? ;)
  22.         while True:
  23.             time.sleep(1)
  24.             if time.strftime("%A") == "Monday" and time.strftime("%H") = "01":
  25.                 # Post a Me Monday at 1AM on Monday (%H is hour in 24-hour notation
  26.                 # so it won't post it at 1PM and %A is (I quote) "Locale's full weekday name".)
  27.                 self.postMeMonday()
  28.  
  29.     def postMeMonday(self):
  30.         self.reddit.submit('lgbteens', 'Me Monday Thread: %s' % (time.strftime('%x')), 'Post your Me Monday here!')
  31.         print("Posted 'Me Monday' thread at %s" % (time.strftime("%A %x %H%p")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement