Created
August 15, 2017 07:07
-
-
Save genderquery/7938318f0dea9c7d4f849ccb28ee8aa3 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 requests | |
import json | |
import csv | |
csvfile = r'C:\Users\avery\Downloads\iehp.csv' | |
url = ('https://ewebserv.iehp.org' | |
'/provider-search/production/api/Provider/GetSpecificProviderList/{itemsPerPage}/{page}') | |
data = { | |
'ProviderType': 'BH', | |
'AcceptingNewMbr': 'true', | |
'Radius' :'15', | |
'ProvLatitude': '33.567588', | |
'ProvLongitude': '-117.250404', | |
'intMilesModifier': '3959', | |
'SearchMethod': 'L' | |
} | |
fieldnames = [ | |
'lastName', | |
'firstName', | |
'phone', | |
'fax', | |
'email', | |
'hours', | |
'locationName', | |
'street', | |
'city', | |
'state', | |
'zip', | |
'speciality'] | |
itemsPerPage = 100 | |
page = 1 | |
totalPages = 1 | |
with open(csvfile, 'w', newline='') as f: | |
writer = csv.DictWriter(f, fieldnames) | |
writer.writeheader() | |
while totalPages >= page: | |
response = requests.post(url.format(itemsPerPage=itemsPerPage, page=page), data) | |
page += 1 | |
jsonBody = response.json() | |
totalPages = jsonBody['totalPages'] | |
providers = jsonBody['providers'] | |
for provider in providers: | |
row = {} | |
addresses = provider['addresses'] | |
specialties = provider['specialties'] | |
for address in addresses: | |
for speciality in specialties: | |
row['lastName'] = provider['lastName'] | |
row['firstName'] = provider['firstName'] | |
row['phone'] = address['phone'] | |
row['fax'] = address['fax'] | |
row['email'] = address['email'] | |
row['hours'] = address['hours'] | |
row['locationName'] = address['locationName'] | |
row['street'] = address['street'] | |
row['city'] = address['city'] | |
row['state'] = address['state'] | |
row['zip'] = address['zip'] | |
row['speciality'] = speciality['specialityDesc'] | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment