forked from RedL0tus/YearProgressBot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.sh
More file actions
58 lines (52 loc) · 1.6 KB
/
main.sh
File metadata and controls
58 lines (52 loc) · 1.6 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Copyright © 2018 Kay <[email protected]>
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See the LICENSE file for more details.
set -e;
function GET_PERCENTAGE {
local CURRENT_YEAR=$(date +%Y);
if [ $((CURRENT_YEAR % 400)) -eq 0 ]; then
local TOTAL_DAYS=366;
elif [ $((CURRENT_YEAR % 100)) -eq 0 ]; then
local TOTAL_DAYS=365;
elif [ $((CURRENT_YEAR % 4)) -eq 0 ]; then
local TOTAL_DAYS=366;
else
local TOTAL_DAYS=365;
fi
CURRENT_DAY=$(echo "$(date +%j) + 0" | bc)
echo $((200*$CURRENT_DAY/$TOTAL_DAYS % 2 + 100*$CURRENT_DAY/$TOTAL_DAYS));
}
function DISPLAY {
local PERCENTAGE=$(GET_PERCENTAGE);
local FILLED=$(($LENGTH*$PERCENTAGE/100));
local BLANK=$(($LENGTH-$FILLED));
local BAR="";
for ((i=0;i<$FILLED;i++)) {
BAR=${BAR}"▓";
}
for ((i=0;i<$BLANK;i++)) {
BAR=${BAR}"░";
}
BAR=${BAR}" "${PERCENTAGE}"%";
echo $BAR;
}
function MAIN {
local BAR="";
local BAR_NOW=$(DISPLAY);
if [ -f "$WORKDIR"/bar ]; then
BAR=$(cat "$WORKDIR"/bar);
fi
echo ">>> Bot started.";
while true; do
BAR_NOW=$(DISPLAY);
if [ "$BAR" != "$BAR_NOW" ]; then
curl -X POST "https://api.telegram.org/bot${API_TOKEN}/sendMessage" -d "chat_id=${CHAT_ID}&text=${BAR_NOW}";
echo $BAR_NOW > "$WORKDIR"/bar;
BAR=$BAR_NOW;
fi
sleep 100;
done
}
MAIN;