Skip to content

Instantly share code, notes, and snippets.

@mheadd
Last active December 23, 2015 22:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheadd/6705590 to your computer and use it in GitHub Desktop.
Save mheadd/6705590 to your computer and use it in GitHub Desktop.
Unix command-line magic for fetching list of L&I licensed entities and saving to a simple CSV file.
curl -s "http://services.phila.gov/PhillyApi/Data/v1.0/licenses?%24filter=substringof(%273381%27,license_type_code)%20eq%20true&%24expand=locations&%24format=json" \
| jq .d.results[] \
| jq '[.pri_contact_last_name, .pri_contact_first_name, .pri_contact_company_name, .pri_contact_address1, .pri_contact_city, .pri_contact_state, .pri_contact_zip, .license_number, .license_type_name, .license_type_code]' \
| jq @csv \
| sed 's/\\//g;s/""/"/g' \
> filename.csv
@mheadd
Copy link
Author

mheadd commented Sep 25, 2013

In this example, looking for registered pawn shops.

Assumes system where this is run has jq installed.

TODO: Convert to a proper shell script and allow input params (e.g., license_type_code) to be passed in.

@mheadd
Copy link
Author

mheadd commented Sep 25, 2013

Could do the same thing for permits, violations, etc.

Could also set up a cron job to run daily and get a fresh list produced each day.

@dgeske
Copy link

dgeske commented Jun 5, 2014

Nice job, this helped me along with my task. Thanks!

One suggested simplification: replace jq @csv | sed 's/\\//g;s/""/"/g' with jq '@csv' --raw-output

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