Created
December 19, 2016 18:41
-
-
Save mousavian/b35098d1f7d0a8ddc1bc2227bc650cf4 to your computer and use it in GitHub Desktop.
control scanner using telegram bot
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
KEY="<telegram-token>" | |
CHATID="<CHATID>" | |
COUNTER=1 | |
replay() { | |
curl -s -d "chat_id=$CHATID&text=$1" "https://api.telegram.org/bot$KEY/sendMessage" | |
} | |
while [[ true ]]; do | |
URL_GET="https://api.telegram.org/bot$KEY/getUpdates?limit=1&update_id=$UPDATEID&offset=$((UPDATEID + 1))" | |
UPDATEID=$(curl -s $URL_GET | python -c "import sys, json; r=json.load(sys.stdin)['result']; out=r[0]['update_id'] if len(r) else 0; print(out)") | |
if [[ $UPDATEID != "0" ]]; then | |
MSG=$(curl -s $URL_GET | \ | |
python -c "import sys, json; r=json.load(sys.stdin)['result']; out=r[0]['message']['text'] if len(r) else 0; print(out)") | |
if [[ $MSG == "Scan" ]]; then | |
replay "ok wait :D" | |
scanimage --format tiff --mode Color --compression JPEG --resolution 200 | convert - "scan/out-$COUNTER.jpg" | |
#passport size: -x 125 -y 180 | |
replay "$COUNTER: done! ;)" | |
((COUNTER++)) | |
fi | |
fi | |
sleep 2s | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment