Create yt-report.sh

This commit is contained in:
Pijus Kamandulis 2019-03-31 01:41:09 +02:00 committed by GitHub
parent c7e97a1c4e
commit 829d416ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 0 deletions

View File

@ -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>/$main_message}"
payload="${payload/<username>/$username}"
payload="${payload/<embed_title>/$embed_title}"
payload="${payload/<embed_description>/$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