Skip to content

Instantly share code, notes, and snippets.

@raianul
Created March 8, 2014 07:14
Show Gist options
  • Save raianul/9426657 to your computer and use it in GitHub Desktop.
Save raianul/9426657 to your computer and use it in GitHub Desktop.
Get Per Diem Value by Event Date and Zipcode
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