Created
February 2, 2020 14:56
-
-
Save ak9999/484122936e5c139ec5e762c1f3210dce to your computer and use it in GitHub Desktop.
Just grabbing JSON data from NYPD Complaint Data Historic from NYC Open Data, and pretty print it. Link: https://data.cityofnewyork.us/Public-Safety/NYPD-Complaint-Data-Historic/qgea-i56i
This file contains hidden or 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 json | |
from datetime import * | |
import pprint | |
from dateutil.relativedelta import * | |
from dateutil.parser import * | |
import requests | |
import pytz | |
EASTERN_TZ = pytz.timezone('US/Eastern') | |
TODAY = datetime.now() | |
TODAY = EASTERN_TZ.localize(TODAY) | |
TODAY_ONE_YEAR_AGO = TODAY - relativedelta(years=1) | |
TIME_DELTA = TODAY_ONE_YEAR_AGO - relativedelta(days=30) | |
TODAY_ONE_YEAR_AGO = TODAY_ONE_YEAR_AGO.strftime('%Y-%m-%d') + 'T00:00:00' | |
TIME_DELTA = TIME_DELTA.strftime('%Y-%m-%d') + 'T00:00:00' | |
API_URL = 'https://data.cityofnewyork.us/resource/qgea-i56i.json' | |
def retrieve(): | |
columns = 'RPT_DT,OFNS_DESC,PD_DESC,CRM_ATPT_CPTD_CD,LAW_CAT_CD,BORO_NM,PREM_TYP_DESC,Latitude,Longitude' | |
filters = { | |
'$limit': 1000, | |
'$select': columns, | |
'$where': 'RPT_DT between \'{}\' and \'{}\''.format(TIME_DELTA, TODAY_ONE_YEAR_AGO) | |
} | |
r = requests.get(API_URL, params=filters) | |
return r.json() | |
if __name__ == '__main__': | |
pprint.pprint(retrieve()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment