Skip to content

Instantly share code, notes, and snippets.

@dotslash
Last active April 14, 2020 07: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 dotslash/dffa202f005239c109e94e1797436187 to your computer and use it in GitHub Desktop.
Save dotslash/dffa202f005239c109e94e1797436187 to your computer and use it in GitHub Desktop.
# Setup
# pip install colored tabulate
# brew install jq (mac)
# sudo apt-get install jq (ubuntu)
alias json_tabulate='python -c "from colored import fg, bg, attr; import json; import fileinput; import tabulate; lines=[line for line in fileinput.input() if line.strip()]; dicts=json.loads(\" \".join(lines)); keys = (dicts and dicts[0].keys()) or []; keys = {k:fg(\"yellow\") + attr(\"bold\")+ k + attr(\"reset\") for k in keys}; print(tabulate.tabulate(dicts, headers=keys))"'
alias update_covid_ind='curl https://api.covid19india.org/data.json > ~/tmp/covid_ind.json'
alias covid_ind_tests='jq ".tested | map({totalpositivecases, totalindividualstested, samplereportedtoday, as_of: .updatetimestamp})" ~/tmp/covid_ind.json | json_tabulate'
alias covid_ind_states='jq ".statewise | map({state, confirmed, new: .deltaconfirmed, last_updated: .lastupdatedtime})" ~/tmp/covid_ind.json | json_tabulate'
alias covid_ind_daily='jq ".cases_time_series | map({date, dailyconfirmed, totalconfirmed}) | .[-20:]" ~/tmp/covid_ind.json | json_tabulate'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment