From e3694d5a5094cdfd671bcd97be56c4e34869c608 Mon Sep 17 00:00:00 2001 From: dataprolet Date: Sun, 10 Aug 2025 15:49:24 +0200 Subject: [PATCH] Add Scripts/arch_linux-news.sh --- Scripts/arch_linux-news.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Scripts/arch_linux-news.sh diff --git a/Scripts/arch_linux-news.sh b/Scripts/arch_linux-news.sh new file mode 100644 index 0000000..ca830c6 --- /dev/null +++ b/Scripts/arch_linux-news.sh @@ -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 \ No newline at end of file