Skip to content

Instantly share code, notes, and snippets.

@mheadd
Last active December 14, 2015 18:22
Show Gist options
  • Save mheadd/a64f9b6b17e7456868d6 to your computer and use it in GitHub Desktop.
Save mheadd/a64f9b6b17e7456868d6 to your computer and use it in GitHub Desktop.

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.

"DC20687","05/12/2015","CORRECTED","47.23 (e)","Violations requiring correction within two weeks (Critical Violations)","Child care service providing care without a staff member trained in First Aid/CPR on site at time of inspection."
"DC20687","05/12/2015","OPEN ","47.41 (j)","Minor violations (General Violations)","At time of inspection floors/walls ceilings were observed not maintained; in disrepair or covered in a toxic finish."
"DC20687","06/10/2014","CORRECTED","47.57 (b)","Violations requiring correction within two weeks (Critical Violations)","At time of inspection it was determined that child care service failed to take any and all necessary action to eliminate potential hazards."
"DC20687","06/10/2014","CORRECTED","47.35 (b)","Minor violations (General Violations)","At time of inspection required hand wash signs were not provided."
"DC20687","06/10/2014","CORRECTED","81.19 (a)(b)","Minor violations (General Violations)","Adequate lighting not provided in food prep area at time of inspection. Foods observed not protected from contamination from light fixture/bulb damage at time of inspection."

Should be possible to iterate over a list of location IDs and append the violations.csv file.

@mheadd
Copy link
Author

mheadd commented Dec 14, 2015

jq displays a warning when the .violations[] array is null (i.e., if an inspection results in no violations), but its not written in the output to the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment