-
Notifications
You must be signed in to change notification settings - Fork 2
/
onleihe-monitor.sh
executable file
·45 lines (33 loc) · 1.15 KB
/
onleihe-monitor.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
#!/bin/bash
. ./repo-config.cfg
. ./telegram-config.cfg
echo $botId
rm -f curr_media_urls.txt
# query links
for url in ${magazinUrls[*]}
do
echo $url
baseUrl=$(echo $url | sed -e 's#[^/]*$##')
curl --silent -o - $url | xsltproc --html extractlinks.xsl - 2> /dev/null 1> curr_media_urls.txt.tmp
while IFS= read -r line
do
echo $baseUrl$line>>curr_media_urls.txt
done < curr_media_urls.txt.tmp
done
# sort all current URLs
sort curr_media_urls.txt | sed -e 's/Details zum Titel: //' > curr_media_urls_sorted.txt
diff --new-line-format="" --unchanged-line-format="" curr_media_urls_sorted.txt known_urls.txt > curr_diff.txt
rm curr_media_urls.txt curr_media_urls_sorted.txt
# read new URLs
while IFS= read -r line
do
curl --silent \
--data-urlencode "chat_id=296922305" \
--data-urlencode "disable_web_page_preview=true" \
--data-urlencode "text=$line " \
"https://api.telegram.org/$botId/sendMessage"
done < curr_diff.txt
# save for next run
cat curr_diff.txt known_urls.txt | sort > known_urls_sorted.txt
mv known_urls_sorted.txt known_urls.txt
rm curr_diff.txt