-
Notifications
You must be signed in to change notification settings - Fork 1
/
alertme.sh
59 lines (53 loc) · 1.38 KB
/
alertme.sh
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
59
#!/bin/bash
#paratmeters
TODAY=$(TZ=":Asia/Kolkata" date)
IST_LOCAL=$(TZ=":Asia/Kolkata" date +%A_%F)
#TG_* parameters are set via /etc/environment variable
TG_BOT_API_KEY=$TG_BOT_API_KEY
TG_CHAT_ID=$TG_CHAT_ID
SCRAPE()
{
python3 scraper.py > "$1"
}
COMPARE()
{
shafirstScrape=$(shasum firstScrape | awk '{ print $1 }')
shasecondScrape=$(shasum secondScrape | awk '{ print $1 }')
if [ "$shafirstScrape" != "$shasecondScrape" ]
then
echo "change detected."
diff secondScrape firstScrape > DIFF.txt
mv secondScrape firstScrape
echo "Running mail script!"
python3 mail.py
rm DIFF.txt
else
echo "No change detected"
# as there are no changes lets just nuke secondScrape.
rm secondScrape
fi
}
main()
{
if [ ! -d logs ]
then
mkdir logs
fi
if [ -f firstScrape ]
then
SCRAPE secondScrape
else
SCRAPE firstScrape
SCRAPE secondScrape
fi
# log those firstScrape and secondScrape html.
echo "================================================================" >> log-"$IST_LOCAL".log
echo "$TODAY" >> logs/log-"$IST_LOCAL".log
echo -e "firstScrape scrape file:\n" >> logs/log-"$IST_LOCAL".log
cat firstScrape >> logs/log-"$IST_LOCAL".log
echo -e "\nsecondScrape scrape\n" >> logs/log-"$IST_LOCAL".log
cat secondScrape >> logs/log-"$IST_LOCAL".log
echo "================================================================" >> log-"$IST_LOCAL".log
COMPARE
}
main