From 829d416ac728aeb26130ce0a50b6ba2a4349cd5e Mon Sep 17 00:00:00 2001 From: Pijus Kamandulis Date: Sun, 31 Mar 2019 01:41:09 +0200 Subject: [PATCH] Create yt-report.sh --- status-webhooks/yt-report.sh | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 status-webhooks/yt-report.sh diff --git a/status-webhooks/yt-report.sh b/status-webhooks/yt-report.sh new file mode 100644 index 0000000..ba08ced --- /dev/null +++ b/status-webhooks/yt-report.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +webhook=`cat webhook.txt` +template=`cat template.txt` +time_now=`date '+%Y-%m-%d %H:%M:%S'` + +archive="/samba/WD_4TB/stuff/VID/yt/archive.txt" +reported="yt_reported.txt" + +# Check if files are the same +cmp --silent $archive $reported && echo "[$time_now] Up to date!" && exit +echo "[$time_now] Not up to date, reporting news!" + +# Set values +username="YT-Reporter" +main_message="Download report" +embed_title="" +embed_description="New downloads:" + +# Get diff +for line in `comm -23 --nocheck-order $archive $reported`; do + if [[ $line != *"youtube"* ]]; then + embed_description="$embed_description\n* $line" + fi +done + +# Build payload +payload="${template//$main_message}" +payload="${payload//$username}" +payload="${payload//$embed_title}" +payload="${payload//$embed_description}" + +# Send payload +echo "[$time_now] Sending:" $payload + +curl --header "Content-Type: application/json" \ + --request POST \ + --data "$payload" \ + "$webhook" + +# Update reported entries +cp $archive $reported