forked from stanfordjournalism/search-script-scrape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
100.py
23 lines (20 loc) · 967 Bytes
/
100.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# The California city whose city manager earns the most total wage per population of its city in 2012
import csv
import requests
from io import BytesIO
from zipfile import ZipFile
YEAR = 2012
def foosalary(row):
return float(row['Total Wages']) / int(row['Entity Population'])
url = 'http://publicpay.ca.gov/Reports/RawExport.aspx?file=%s_City.zip' % YEAR
print("Downloading:", url)
resp = requests.get(url)
with ZipFile(BytesIO(resp.content)) as zfile:
fname = zfile.filelist[0].filename # 2012_City.csv
rows = zfile.read(fname).decode('latin-1').splitlines()
# first 4 lines are Disclaimer lines
managers = [r for r in csv.DictReader(rows[4:]) if r['Position'].lower() == 'city manager'
and r['Total Wages']]
topman = max(managers, key = foosalary)
print("City: %s; Pay-per-Capita: $%s" % (topman['Entity Name'], int(foosalary(topman))))
# City: Industry; Pay-per-Capita: $465