Last active
April 24, 2019 13:17
-
-
Save alexshpilkin/7c3195c9c8105638741c44b94d41cebf to your computer and use it in GitHub Desktop.
Add diffs to results posts
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/sh -eu | |
| # NB: Contains literal tabs | |
| caption() { | |
| python -c ' | |
| from os import getenv | |
| from sys import argv | |
| from telegram import Bot | |
| from telegram.error import BadRequest, TimedOut | |
| bot = Bot(token=getenv("TOKEN")) | |
| while True: | |
| try: | |
| bot.edit_message_caption(chat_id=getenv("CHAT"), | |
| message_id=argv[1], | |
| caption=argv[2], | |
| parse_mode="HTML") | |
| except BadRequest: | |
| break | |
| except TimedOut: | |
| pass | |
| else: | |
| break | |
| ' "$@" | |
| } | |
| SG="lines%10==1 && lines%100!=11" | |
| DU="lines%10>=2 && lines%10<=4 && (lines%100<10 || lines%100>=20)" | |
| ROOT=https://alexshpilkin.github.io/uk-pres2019/ | |
| DIFF="diff -u1 -F^region" | |
| prev= | |
| ( cd Updates; ls results.*; ) | \ | |
| while read -r curr; do | |
| if [ -z "$prev" ]; then prev=$curr; continue; fi # First file | |
| diff=${curr%.tsv}.html | |
| if [ -f "Diffs/$diff" ]; then prev=$curr; continue; fi # Exported | |
| echo "export $diff" | |
| tac Updates/.hat | while IFS=' ' read -r msgid digest file; do | |
| if [ "$file" = "$curr" ]; then | |
| if [ "$file" != "$curr" ] || [ "$msgid" = ! ]; then | |
| echo "zombie $curr"; continue | |
| fi | |
| lines=$(diff -y --suppress-common-lines \ | |
| "Updates/$prev" "Updates/$curr" | \ | |
| wc -l) | |
| $DIFF --color=always "Updates/$prev" "Updates/$curr" | \ | |
| /usr/share/git/diff-highlight/diff-highlight | \ | |
| aha -t "$DIFF $prev $curr" | tr -d '\r' > "Diffs/$diff" | |
| cd Diffs | |
| git add "$diff" | |
| git commit -m "Add $diff" | |
| git push | |
| cd .. | |
| if (( $SG )); then caption="$lines изменение" | |
| elif (( $DU )); then caption="$lines изменения" | |
| else caption="$lines изменений" | |
| fi | |
| caption "$msgid" "<a href='$ROOT$diff'>$caption</a>" | |
| fi | |
| done | |
| prev=$curr | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment