diff --git a/santiago.sh b/santiago.sh new file mode 100644 index 0000000..bd387c4 --- /dev/null +++ b/santiago.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# fanta - https://git.56k.es/fanta/santiago +# dependencies: toot + +scriptDir="/home/fanta/repos/santiago" # The bot path +user=$(whoami) +opt="$1" +version="0.1" +fileNotifications="/tmp/notifications.txt" + +function who { if [ "$(whoami)" = "root" ]; then exit; fi } + +function checkDeps { + tootValue="$(toot | head -1)" + if [[ $tootValue != "toot - a Mastodon CLI client" ]]; then echo "Please install toot"; exit; fi +} + +function login { + toot login +} + +function run { + toot notifications -m --no-color | grep -i "ID " | cut -d " " -f 2 | head -20 > $fileNotifications + while read not; do + toot=$(toot thread "$not" | grep -i "@caminosantiago añade " | head -1) + if [ -z "$toot" ] + then echo "Toot no valido" + else + #toot thread "$not" + walkerName=$(toot thread "$not" --no-color | head -2 | tail -1 | cut -d "@" -f 2,3 | cut -d " " -f 1) + walkerDate=$(toot thread "$not" --no-color | head -2 | tail -1 | cut -d "@" -f 2,3 | rev | cut -d " " -f 1,2 | rev) + walkerFile=$(echo "$scriptDir/walkers/$walkerName") + walkerKm=3 + + if [ -f "$walkerFile" ]; then + walkerDate2=$(cat $walkerFile | grep "$walkerDate" | head -1) + if [ -z "$walkerDate2" ]; then + echo "Nuevo kilometraje de $walkerName" + echo "$walkerDate;$walkerKm" >> $walkerFile + else + echo "Toot ya añadido previamente" + fi + else + touch $walkerFile + echo "Primer kilometraje de $walkerName" + echo "$walkerDate;$walkerKm" > $walkerFile + fi + fi + done < $fileNotifications +} + +function help { + echo -e "santiago $version - fanta \n" + echo "-l Login the mastodon bot account\n" + echo "-r Run the bot\n" + echo "-h Show this help\n" +} + +function checkOpt { + if [ -z "$opt" ]; then help; fi + if [ "$opt" = "-h" ]; then help; fi + if [ "$opt" = "-l" ]; then login; fi + if [ "$opt" = "-r" ]; then run; fi +} + +function main() { + who + checkDeps + checkOpt +} + +main diff --git a/walkers/fanta@mastodon.green b/walkers/fanta@mastodon.green new file mode 100644 index 0000000..f469095 --- /dev/null +++ b/walkers/fanta@mastodon.green @@ -0,0 +1 @@ +2025-01-19 11:43;3