Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import reddit
- bills = []
- messageRecipients = ['brown_paper_bag', 'Ben347']
- user = "Reddica_Bot"
- password = removed :P
- redditWrapper = reddit.Reddit(user_agent="Reddica Bot by /u/Ben347")
- redditWrapper.login(user, password)
- subreddit = redditWrapper.get_subreddit("WorldofPolitics")
- def log(text):
- print "%s - %s" % (time.time(), text)
- def isNew(post):
- for timePosted, title, url in bills:
- if title == post:
- return False
- return True
- def checkForNewBills():
- recentPosts = subreddit.get_new_by_date(limit=10)
- for post in recentPosts:
- if '[bill]' in post.title.lower():
- if isNew(post.title):
- bills.append((time.time(), post.title, post.short_link))
- log("Found new bill: %s" % (post.title))
- def sendMessages():
- oldBills = []
- for i in range(len(bills)):
- timePosted, title, url = bills[i]
- if time.time() - timePosted >= (60 * 60 * 48):
- oldBills.append(i)
- subject = 'Bill is ready for action'
- message = 'Bill "%s" has been posted for 48 hours: %s.' % (title, url)
- for recipient in messageRecipients:
- redditWrapper.compose_message(recipient, subject, message)
- log("Sent alert to user %s" % (recipient))
- time.sleep(2)
- oldBills = sorted(oldBills, reverse=True)
- for i in oldBills:
- bills.pop(i)
- while True:
- time.sleep(10)
- checkForNewBills()
- sendMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement