Skip to content

Instantly share code, notes, and snippets.

@jehiah
Created June 27, 2024 18:34
Show Gist options
  • Save jehiah/b9c754f2699c2c510ad959d327e402cf to your computer and use it in GitHub Desktop.
Save jehiah/b9c754f2699c2c510ad959d327e402cf to your computer and use it in GitHub Desktop.
Calculate key dates for NYC Legislation
#!/bin/sh
# Calculate key dates for NYC legislation
# using data from https://github.com/jehiah/nyc_legislation
if ! command -v jq >/dev/null; then
echo "missing jq; brew install jq"
exit 1
fi
if ! command -v json2csv >/dev/null; then
echo "missing json2csv - see https://github.com/jehiah/json2csv/releases"
exit 1
fi
# 27 'Introduced by Council',
# 15 'Hearing on P-C Item by Comm'
# 54 'Hearing Held by Committee'
# 33 'Amended by Committee',
# 32 'Approved by Committee',
# 25 'P-C Item Approved by Comm'
# 68 'Approved by Council',
CURRENT_YEAR="2024"
START=${START:-"2014"}
while [ $START -le $CURRENT_YEAR ]; do
RECENT_YEARS+=( "${START}" )
((START++))
done
mkdir -p build
for YEAR in ${RECENT_YEARS[*]}; do
if ! [ -e introduction/$YEAR ]; then
continue
fi
echo "processing introductions/${YEAR}/*.json"
jq -c -s "map({File, TypeName, Name, Title, StatusName, BodyID, BodyName, IntroDate, Sponsors: ([.Sponsors[]? | select(.ID != 0)] | length), PrimeSponsor: (.Sponsors[0]?.FullName), FirstHearingDate: ([.History[]? | select(.ActionID==54 or .ActionID == 15)])[0]?.Date, ApprovedByCommitteeDate: ([.History[]? | select(.ActionID==32 or .ActionID == 25)])[0]?.Date, ApprovedByCouncilDate: ([.History[]? | select(.ActionID==68)])[0]?.Date})" introduction/$YEAR/????.json > build/intro_${YEAR}_dates.json
done
# build combined csv file
echo "building intro_dates_2014-2024.csv"
jq -c '.[]' build/intro_*_dates.json | json2csv -p -k TypeName,File,Name,Title,StatusName,BodyID,BodyName,PrimeSponsor,sponsors,IntroDate,FirstHearingDate,ApprovedByCommitteeDate,ApprovedByCouncilDate > intro_dates_2014-2024.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment