-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
48 lines (36 loc) · 1.57 KB
/
bot.py
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
42
43
44
45
46
47
48
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import logging
import os
import time
from datetime import datetime
import tweepy
import requests
auth = tweepy.OAuthHandler(os.environ['CONSUMER_KEY'], os.environ['CONSUMER_SECRET'])
auth.set_access_token(os.environ['ACCESS_KEY'], os.environ['ACCESS_SECRET'])
api = tweepy.API(auth)
# would want a db in the future if I do more complex things
processed_files = []
fec_params = {
'api_key': os.environ['FEC_API_KEY'],
# don't want to flood the feed with repeats
'min_receipt_date': datetime.now(),
}
logging.info('Running...')
while True:
filings = requests.get('https://api.open.fec.gov/v1/efile/filings/?sort=-receipt_date&per_page=70', params=fec_params).json()
if 'results' in filings:
for record in filings['results']:
if record['file_number'] not in processed_files:
committee_name = str(record['committee_name'] or '')[:116]
candidate_name = str(record['candidate_name'] or '')[:116]
link = 'http://docquery.fec.gov/cgi-bin/forms/{0}/{1}'.format(record['committee_id'], record['file_number'])
message = committee_name + candidate_name + ' ' + link
if record['amends_file'] is not None:
message = committee_name[:106] + ' ' + link +' amendment'
api.update_status(message)
processed_files.append(record['file_number'])
if len(processed_files) > 500:
processed_files = processed_files[50:]
time.sleep(10)