forked from njl/progcom
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpull_updates.py
executable file
·83 lines (64 loc) · 2.1 KB
/
pull_updates.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import logging
import os
from hashlib import sha1
from calendar import timegm
from datetime import datetime
import sys
import pytz
import requests
from raven import Client
from simplejson import JSONDecodeError
from requests.exceptions import RequestException
import logic as l
API_KEY = os.environ['PYCON_API_KEY']
API_SECRET = os.environ['PYCON_API_SECRET']
API_HOST = os.environ['PYCON_API_HOST']
PYBAY_API_TOKEN = "test"
API_TOKEN_PATH = '/home/pybay/api_token.txt'
log_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'logging.conf')
logging.config.fileConfig(log_path)
log = logging.getLogger("worker")
if os.path.exists(API_TOKEN_PATH):
with open(API_TOKEN_PATH) as f:
token = f.read().strip()
PYBAY_API_TOKEN = token
def api_call(api_suffix):
result = requests.get(
"http://pybay.com/api/{}".format(api_suffix),
params={'token': PYBAY_API_TOKEN},
)
result = result.json()
return result
def fetch_ids():
raw = api_call('undecided_proposals')
rv = [x['id'] for x in raw['data']]
return rv
def fetch_talk(id):
rv = api_call('proposals/{}/'.format(id))
if not rv or 'data' not in rv:
return {}
rv = rv['data']
rv['authors'] = rv['speakers']
del rv['speakers']
rv.update(rv['details'])
del rv['details']
# NOTE: Since we changed the field `what_attendees_will_learn` to
# `what_will_attendees_learn` in PyBay (https://github.com/pybay/pybay/pull/224)
# This will case issues in progcom. To avoid this issue, let's rename the field
# before it gets ingested by Progcom
what_attendees_will_learn = rv.pop('what_attendees_will_learn')
rv['what_will_attendees_learn'] = what_attendees_will_learn
return rv
def main():
for id in fetch_ids():
log.info('FETCHING {}'.format(id))
try:
proposal = fetch_talk(id)
if proposal:
l.add_proposal(proposal)
except Exception as e:
log.error('ERROR FETCHING {}: {}'.format(id, repr(e)))
if __name__ == '__main__':
main()