Skip to content

Instantly share code, notes, and snippets.

@mheadd
Last active July 21, 2017 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheadd/117121092e82c537a599631542121d48 to your computer and use it in GitHub Desktop.
Save mheadd/117121092e82c537a599631542121d48 to your computer and use it in GitHub Desktop.
A simple script to pull down businesses by license type and display in a searchable HTML table.
##!/bin/bash
# License number (e.g., 3381).
LICENSE_TYPE=$1
# The name of the file to populate with records.
FILE_NAME=$2
echo "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" > $FILE_NAME
curl -s "http://services.phila.gov/PhillyApi/Data/v1.0/licenses?%24filter=substringof(%27$LICENSE_TYPE%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 --raw-output >> $FILE_NAME
csvtotable $FILE_NAME --serve
@mheadd
Copy link
Author

mheadd commented Jul 21, 2017

Example above uses an API from the City of Philadelphia's Department of Licenses & Inspections. This is an OData API that returns JSON.

Make the file executable: chomd +x find-biz-by-license.sh

Execute thusly (for example, using registered pawn shops): ~$ ./find-biz-by-license.sh 3381 pawn_shops.csv

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