Skip to content

Instantly share code, notes, and snippets.

@prabhakaran9397
Last active May 15, 2021 12:11
Show Gist options
  • Save prabhakaran9397/6b95d6da17c03563c00ac9a9aa568f17 to your computer and use it in GitHub Desktop.
Save prabhakaran9397/6b95d6da17c03563c00ac9a9aa568f17 to your computer and use it in GitHub Desktop.
#!/bin/bash
baseurl=https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict
did=571
rm -rf .response.ndjson report.html
for day in {0..30}; do
cdate=$(date -d "+$day day" +%d-%m-%Y)
url="$baseurl?district_id=$did&date=$cdate"
echo "$url"
curl -s -o- \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-US,en;q=0.5' \
-H 'Origin: https://selfregistration.cowin.gov.in' \
-H 'Connection: keep-alive' \
-H 'Referer: https://selfregistration.cowin.gov.in/' \
$url >>.response.ndjson
echo >> .response.ndjson
sleep 1
done
filtered=$(cat .response.ndjson | grep -F '{"centers"' | jq -c '
.centers[]
| . + .sessions[]
| {
id: .session_id,
name: .name,
address: .address,
min_age: .min_age_limit,
date: .date | strptime("%d-%m-%Y") | strftime("%Y-%m-%d"),
vaccine: .vaccine,
availablity: .available_capacity,
fee_type: .fee_type
}
| select (.availablity > 0 and .min_age == 18)
')
[ -z "$filtered" ] && exit 1
echo $filtered | jq -sr '
unique_by(.id)
| sort_by(.min_age, .date,-.availablity)
| (
["NAME", "MIN AGE", "DATE", "VACCINE", "AVAILABLITY", "FEE TYPE"]
), (
.[]
| [.name, .min_age, .date, .vaccine, .availablity, .fee_type]
)
| @csv
' | sed 's/"//g;s/\\t/\$/g' > report.txt
echo '<table width="2000px">' >> report.html
head -n 1 report.txt | sed -e 's/^/<tr><td width="300px"><b>/' -e 's/,/<\/b><\/td><td width="300px"><b>/g' -e 's/$/<\/b><\/td><\/tr>/' >> report.html
tail -n +2 report.txt | sed -e 's/^/<tr><td width="300px">/' -e 's/,/<\/td><td width="300px">/g' -e 's/$/<\/td><\/tr>/' >> report.html
echo "</table>" >> report.html
mailx -a 'Content-Type: text/html' -s "Covid Vaccine Slots" '<email ID>' <report.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment