Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #
- # Reddit 'Me Monday' poster.
- # by svkampen, 2012.
- import reddit # This is a pypi package; installable via easy_install reddit or pip install reddit -U
- import time
- class MeMondayPoster():
- def __init__(self):
- self.reddit = reddit.Reddit(user_agent='me_monday_poster')
- # This is not a real user, ofcourse.
- self.username = 'memondaybot'
- self.password = 'i_post_me_mondays'
- self.reddit.login(self.username, self.password)
- self.startTimer()
- def startTimer(self):
- # This will probably take up your CPU; I am not sure how to fix.. (I know quite a bit
- # of Python but preserving CPU: not really) Right now as a fix I have added a time.sleep for every
- # loop to limit cpu usage. I mean, does it really matter if the post arrives one second later? ;)
- while True:
- time.sleep(1)
- if time.strftime("%A") == "Monday" and time.strftime("%H") = "01":
- # Post a Me Monday at 1AM on Monday (%H is hour in 24-hour notation
- # so it won't post it at 1PM and %A is (I quote) "Locale's full weekday name".)
- self.postMeMonday()
- def postMeMonday(self):
- self.reddit.submit('lgbteens', 'Me Monday Thread: %s' % (time.strftime('%x')), 'Post your Me Monday here!')
- print("Posted 'Me Monday' thread at %s" % (time.strftime("%A %x %H%p")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement