Skip to content

Instantly share code, notes, and snippets.

@mheadd
Last active Dec 23, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@mheadd 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

This comment has been minimized.

Copy link
Owner Author

@mheadd 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

This comment has been minimized.

Copy link

@dgeske 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