-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsend-diff.sh
More file actions
executable file
·40 lines (31 loc) · 799 Bytes
/
send-diff.sh
File metadata and controls
executable file
·40 lines (31 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
BOT_ID=__BOT_ID__
CHAT_ID=__CHAT_ID__
MPG_TOKEN=__MPG_TOKEN__
LOG_FILE=/home/pi/java/mpg/log-extract.log
function log {
echo ${*}
echo [`date +"%D"` - `date +"%T"`] -- $COUNTRY -- ${*} >> ${LOG_FILE}
}
if [ -z "$1" ]
then
log 'No parameter'
exit 1;
fi
if [ -z "$2" ]
then
log 'No league id'
exit 1;
fi
FILENAME_DIFF=mpg-$1.diff
FILENAME_CSV=mpg-$1.csv
COUNTRY=$1
java -jar mpg-extract.jar $FILENAME_CSV $2 $MPG_TOKEN
git diff -U0 $FILENAME_CSV | grep '^[+-]' | grep -Ev '^(--- a/|\+\+\+ b/)' > $FILENAME_DIFF
diffText=`cat $FILENAME_DIFF`
if [[ $diffText = *[!\ ]* ]]; then
curl --data chat_id=$CHAT_ID --data-urlencode "text=$diffText" "https://api.telegram.org/$BOT_ID/sendMessage"
git commit $FILENAME_CSV -m 'automatical commit'
else
log 'no changes'
fi