Created
August 3, 2024 10:20
-
-
Save andyollylarkin/3692bee9ee69c22663036bc860affd3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
curr_date=${1:-$(date +"%Y")}; | |
if [[ ${#curr_date} > 4 ]]; then | |
echo "Illegal year format: ${curr_date}" | |
exit 1; | |
fi | |
echo Grub working date of $curr_date year; | |
curl -w '' -s "https://production-calendar.ru/get-period/428b30c3b72f354ce5a2874148adc050/ru/${curr_date}/json"|jq \ | |
-r '[.'days'.[] | {date,working_hours}|select((.'date') and (.'working_hours' > 0))]'|jq -r '["date", "working_hours"], (.[] | [.date, .working_hours]) | @csv'|tr \ | |
-d '"'|tr '.' '-'|tail -n +2|awk -F',' '{ split($1, parts, "-"); printf "%s-%s-%s,%d\n", parts[3],parts[2],parts[1],$2;}' > /tmp/wd.csv; | |
tmp_file=$(mktemp); | |
cat /tmp/wd.csv > $tmp_file; | |
echo -e '"date","working_hours"' > /tmp/wd.csv; | |
cat $tmp_file >> /tmp/wd.csv; | |
cp /tmp/wd.csv .; | |
rm /tmp/wd.csv; | |
rm $tmp_file; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment