Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .slugignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package.json
package-lock.json
yarn.lock
28 changes: 28 additions & 0 deletions events/fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import requests
import time
import json
import sys

if len(sys.argv) < 2:
print('usage: fetch.py <output file>')
exit()

mobilize_api_events_url = 'https://api.mobilize.us/v1/organizations/1316/events?timeslot_start=gte_now&is_virtual=false&per_page=100'

next = mobilize_api_events_url

events = []

while next is not None:

r = requests.get(next)
resp = r.json()
events += resp['data']
next = resp['next']
print('requested {} next {}'.format(r.url, next))
# be nice to the api
time.sleep(5)


with open(sys.argv[1], 'w') as f:
f.write(json.dumps(events))
38 changes: 38 additions & 0 deletions events/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json
import sys

events = []

if len(sys.argv) < 3:
print("usage: filter.py <input file> <output file>")
exit()

with open(sys.argv[1]) as f:
events = json.loads(f.read())

slim_events = []

for e in events:

# if the event doesnt have a location then we can skip it.
if 'location' not in e['location'] or 'latitude' not in e['location']['location'] or e['location']['location']['latitude'] is None:
continue

# remove attributes we arent going to display.
del e['location']['congressional_district']
del e['location']['state_leg_district']
del e['location']['state_senate_district']

slim_events.append({
'id': e['id'],
'browser_url': e['browser_url'],
'location': e['location'],
'title': e['title'],
'timeslots': e['timeslots'][0:3],
'timeslot_count': len(e['timeslots']),
'featured_image_url': e['featured_image_url'],
'event_type': e['event_type']
})

with open(sys.argv[2], 'w') as f:
f.write(json.dumps(slim_events))
12 changes: 12 additions & 0 deletions fetch-events.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -ex

python3 events/fetch.py all-events.json

python3 events/filter.py all-events.json events.json

gzip events.json

aws s3 cp events.json.gz $S3_PATH/events.json --acl public-read --content-encoding gzip --content-type "application/json"

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests==2.22.0
awscli==1.16.248
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.7.3