Created
April 5, 2017 23:57
-
-
Save genderquery/081069776efc1cda9248ade97184b152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
import csv | |
layer = 5 | |
field_names = ('CATEGORY', 'SIGNTYPE', 'STANDARDTEXT') | |
max_records = 1000 | |
url = 'http://gisrevprxy.seattle.gov/ArcGIS/rest/services/SDOT_EXT/sdot_parking/MapServer/{0}/query'.format(layer) | |
count_params = { | |
'f': 'json', | |
'where': '1=1', | |
'returnCountOnly': 'true' | |
} | |
page_clause = 'OBJECTID > {0}' | |
params = { | |
'f': 'json', | |
'outFields': ','.join(field_names), | |
'returnGeometry': 'false', | |
} | |
response = requests.get(url, count_params) | |
json = response.json() | |
record_count = json['count'] | |
writer = csv.DictWriter(sys.stdout, field_names) | |
writer.writeheader() | |
for record_index in range(0, record_count, max_records): | |
params['where'] = page_clause.format(record_index) | |
response = requests.get(url, params) | |
json = response.json() | |
for feature in json['features']: | |
writer.writerow(feature['attributes']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment