This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathflatten.py
64 lines (52 loc) · 1.61 KB
/
flatten.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
import requests
import os
import pymongo
from django.template.defaultfilters import slugify
SERVER = 'http://localhost:9999'
BASE = 'html/'
db = pymongo.MongoClient()['fiftystates']
def flatten(url):
filename = os.path.join(BASE, url.lstrip('/'), 'index.html')
if os.path.exists(filename):
print('skipping', filename)
return
resp = requests.get(SERVER + url)
if resp.status_code != 200:
print('broken', url)
return
try:
os.makedirs(os.path.dirname(filename))
except OSError:
pass
with open(filename, 'wb') as out:
out.write(resp.content)
def flatten_basics():
flatten('/')
flatten('/reportcard/')
# for mdata in db.metadata.find():
# state = mdata['_id']
# flatten(f'/{state}/')
# flatten(f'/{state}/legislators/')
# flatten(f'/{state}/committees/')
# flatten(f'/{state}/bills/')
def flatten_legislators():
for leg in db.legislators.find():
state = leg['state']
slug = slugify(leg['full_name'])
flatten(f'/{state}/legislators/{leg["leg_id"]}/{slug}/')
flatten(f'/{state}/legislators/{leg["leg_id"]}/')
# flatten(f'/{state}/legislators/{leg["leg_id"]}/votes')
def flatten_bills():
for b in db.bills.find():
session = b['session']
bill_id = b['bill_id']
state = b['state']
flatten(f'/{state}/bills/{session}/{bill_id}/')
def flatten_votes():
for v in db.votes.find():
state = v['state']
flatten(f'/{state}/votes/{v["_id"]}/')
# flatten_basics()
# flatten_legislators()
# flatten_bills()
flatten_votes()