Created
March 8, 2014 07:14
-
-
Save raianul/9426657 to your computer and use it in GitHub Desktop.
Get Per Diem Value by Event Date and Zipcode
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 datetime | |
PER_DIEM_API = 'https://explore.data.gov/resource/perdiem.json' | |
def get(params): | |
r = requests.get(PER_DIEM_API, params=params) | |
return r.json() | |
# event date and zip code should be send as parameter | |
date = '03-08-2014' | |
event_data = datetime.datetime.strptime(date, '%d-%m-%Y').date() | |
month = event_data.strftime("%b") | |
year = event_data.strftime("%Y") | |
zipcode = '46899' | |
# Set fiscalyear | |
# state | |
params = { | |
'fiscalyear': year, | |
'zip': zipcode, | |
} | |
results = get(params) or None | |
if results: | |
results = results[0] | |
print results[month.lower()] | |
else: | |
print "invalid request" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment