forked from kylejfrost/Congress_Bill_Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmission_bot.py
More file actions
41 lines (30 loc) · 966 Bytes
/
submission_bot.py
File metadata and controls
41 lines (30 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
import const
import utils
import praw
import sys
import analytics
from propub import ProPublica
reddit = praw.Reddit(client_id=const.CLIENT_ID,
client_secret=const.CLIENT_SECRET,
user_agent=const.USER_AGENT,
username=const.USERNAME,
password=const.PASSWORD)
pp = ProPublica(const.PROPUB_KEY)
def bot():
for submission in reddit.subreddit(sys.argv[1]).stream.submissions():
if "congress.gov/bill" not in submission.url:
continue
congress, bill_id = utils.parse_url(submission.url)
bill = pp.get_bill(congress, bill_id)
comment = utils.format_comment_from_bill(bill)
submission.reply(comment)
print "I replied to: " + submission.shortlink
analytics.db_insert(bill, submission.author.name, submission.subreddit, "S")
while True:
try:
bot()
except KeyboardInterrupt:
exit()
except:
pass