Skip to content

Instantly share code, notes, and snippets.

View mheadd's full-sized avatar

Mark Headd (He/Him) mheadd

View GitHub Profile
{
"result": [
{
"isForDemo": false,
"hostedACA": true,
"display": "BUTTSCO",
"enabled": true,
"serviceProviderCode": "BUTTSCO",
"name": "BUTTSCO"
},
location_id street_number street_name street_suffix permit_type_code status
760148 00271 RIPKA ST NEWCON COMPLETED
760148 00271 RIPKA ST ENTIRE ACTIVE
760148 00271 RIPKA ST NEWIN EXPIRED
760148 00271 RIPKA ST NEWIN ACTIVE
760148 00271 RIPKA ST EZPLUM ACTIVE
761757 00271 RIPKA ST EZELEC ACTIVE
760148 00271 RIPKA ST WARMA ACTIVE
761757 00271 RIPKA ST EZPLUM COMPLETED

Using Chris Whong's JSON proxy for daycare data, create a CSV file with details of violations for a specific location. Assumes jq is installed.

~$ curl -s http://daycareproxy.herokuapp.com/id/DC20687 \
| jq '.inspections[] | .date as $date | .violations[] | .date |=  $date | .id = "DC20687" | [.id,.date,.status,.subSection,.category,.summary] | @csv' \
| sed 's/\\r\\n//g;s/\\//g;s/""/"/g;s/  //g' \
> > violations.csv

Produces a violations.csv file with the following contents.

{
"result": [
{
"isForDemo": false,
"hostedACA": true,
"display": "BUTTSCO",
"enabled": true,
"serviceProviderCode": "BUTTSCO",
"name": "BUTTSCO"
},
@mheadd
mheadd / Onondaga_County_Restaurant_Inspections_clean.csv
Last active November 12, 2015 20:19
Chunked Transfer Encoding Example
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 3.
FACILITY,ADDRESS,LAST_INSPECTED,VIOLATIONS,TOTAL_NUM_CRITICAL_VIOLATIONS,TOTAL_NUM_CRIT_NOT_CORRECTED,TOTAL_NUM_NONCRITICAL_VIOLATIONS,DESCRIPTION,LOCAL_HEALTH_DEPARTMENT,COUNTY,FACILITY_ADDRESS,CITY,ZIP_CODE,NYSDOH_GAZETTEER_1980,MUNICIPALITY,OPERATION_NAME,PERMIT_EXPIRATION_DATE,PERMITTED_DBA,PERMITTED_CORP_NAME,PERM_OPERATOR_LAST_NAME,PERM_OPERATOR_FIRST_NAME,NYS_HEALTH_OPERATION_ID,INSPECTION_TYPE,INSPECTOR_ID,INSPECTION_COMMENTS,FOOD_SERVICE_FACILITY_STATE,Location1
Abbotts Frozen Custard ,"4282 Fay ROAD, Syracuse",04/08/2015,No violations found.,0,0,0,Food Service Establishment - Ice Cream Store,Onondaga County,ONONDAGA,4282 Fay ROAD,Syracuse,13219 ,336100,ONONDAGA,Abbotts Frozen Custard,01/31/2016,,"Dixon & Knowles, LLC",Dixon,Douglas,535612,Inspection,,Conditions satisfactory to operate at this time.,NY,"(43.027484, -76.217622)"
Abbott's Village Tavern ,"6 EAST Main STREET, Marcellus",05/01/2015,"Item 8D- Single service items reused, improperly stored, dispensed, not
@mheadd
mheadd / permit-lookup.php
Created October 23, 2015 17:10
A simple Tropo app to lookup permit status using an Open Permit API
<?php
// Open permit API
define("URL_BASE", "http://mdc.openpermit.org/op/permits");
// Simple utility method to make API call.
function getPermitData($num) {
$url = URL_BASE . "?number=" . $num;
$permit_data = file_get_contents($url);
return json_decode($permit_data);
@mheadd
mheadd / get-data.md
Last active October 9, 2015 13:58
Getting vacancy licenses from the Philadelphia L&I API

Download date on vacancy licesnses by month (the API limits resonses to 1000 records per request). For example:

curl -s 'http://services.phila.gov/PhillyApi/Data/v1.0/licenses?$filter=(issued_datetime%20gt%20datetime%272015-01-01%27)%20and%20(issued_datetime%20lt%20datetime%272015-01-31%27)%20and%20(license_type_name%20eq%20%27RESIDENTIAL%20RES_VACANT%27)&$expand=locations&$format=json'

This will return a JSON response like this:

{
@mheadd
mheadd / sql-search-example.md
Last active August 29, 2015 14:25
Example of how to use SQL Search API to rename columns

HTTP GET on this:

http://www.civicdata.com/api/action/datastore_search_sql?sql=SELECT "PermitNum", 
"Description", "AppliedDate", "IssuedDate", "CompletedDate", 
"OriginalAddress1", "OriginalCity", "OriginalState", "OriginalZip", "PermitClass",
"PermitClassMapped","StatusCurrent","StatusCurrentMapped","WorkClass","WorkClassMapped",
"PermitType","PermitTypeMapped","PermitTypeDesc", "StatusDate","TotalSqFt","Link",
"EstProjectCost","HousingUnits","PIN","ContractorCompanyName","ContractorTrade",
"ContractorTradeMapped","ContractorLicNum","ContractorStateLic","ContractorFullName",
@mheadd
mheadd / philly-open-data-policy.md
Last active January 26, 2016 23:56
Excerpt from the City of Philadelphia Open Records Policy & Open Data Policy

Open Data & Government Transparency

WHEREAS, the City of Philadelphia is committed to creating a high level of openness and transparency in government; and

WHEREAS, the three principles of transparency, participation, and collaboration form the cornerstone of an open government; and

WHEREAS, the City's participation as a founding and vital partner in the open data consortium has provided a model for transparency on which the City should continue to build; and

WHEREAS, more City data sets should be published and made available via an Open Data Portal which will provide access to information and a mechanism for public feedback and participation; and