Add Scripts/arch_linux-news.sh
This commit is contained in:
38
Scripts/arch_linux-news.sh
Normal file
38
Scripts/arch_linux-news.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eou pipefail
|
||||
|
||||
# Variables
|
||||
CHAT_ID=""
|
||||
TOKEN=""
|
||||
URL="https://archlinux.org"
|
||||
RECENT_FILE="/tmp/recent_arch_news"
|
||||
|
||||
# Creates file if not existing
|
||||
if [[ ! -f "${RECENT_FILE}" ]]; then
|
||||
touch "${RECENT_FILE}"
|
||||
fi
|
||||
|
||||
# Check if recent news has already been send
|
||||
LATEST_NEWS=$(curl -s "$URL/news/" | xmllint --html --xpath 'string(//table[@id="article-list"]/tbody/tr[1]/td[2]/a/@href)' - 2>/dev/null)
|
||||
RECENT_NEWS=$(cat "${RECENT_FILE}")
|
||||
|
||||
if [[ "${LATEST_NEWS}" == "${RECENT_NEWS}" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Takes URL and title to make message text
|
||||
NEWS_URL="${URL}${LATEST_NEWS}"
|
||||
TITEL=$(curl -s "${NEWS_URL}" | xmllint --html --xpath 'string(//div[@id="content"]//h2)' - 2>/dev/null)
|
||||
TEXT="${TITEL}: ${NEWS_URL}"
|
||||
|
||||
# Send message
|
||||
send_message(){
|
||||
curl -s -X POST "https://api.telegram.org/bot${TOKEN}/sendMessage" \
|
||||
-d chat_id="${CHAT_ID}" -d text="${TEXT}"
|
||||
}
|
||||
|
||||
# If message was send save news to file
|
||||
if send_message; then
|
||||
echo "${LATEST_NEWS}" > "${RECENT_FILE}"
|
||||
fi
|
Reference in New Issue
Block a user