From d19fe2e4bf75d5d72a78257ca6f06e3d85ecb151 Mon Sep 17 00:00:00 2001 From: Ken Fallon Date: Sun, 21 Sep 2025 19:19:20 +0200 Subject: [PATCH] Cron automations --- workflow/check_feeds.bash | 26 ++++++++ workflow/export-jsons-stats.bash | 8 +++ workflow/hpr-publish.bash | 111 ++++++++++++++++++++++++++----- workflow/hpr_db_backup.bash | 2 + workflow/process_episode.bash | 1 - 5 files changed, 131 insertions(+), 17 deletions(-) create mode 100755 workflow/check_feeds.bash create mode 100755 workflow/export-jsons-stats.bash diff --git a/workflow/check_feeds.bash b/workflow/check_feeds.bash new file mode 100755 index 0000000..44211be --- /dev/null +++ b/workflow/check_feeds.bash @@ -0,0 +1,26 @@ +#!/bin/bash + +feed_dir="$HOME/tmp/hpr/rss" + +wget https://hackerpublicradio.org/hpr_opus_rss.php -O "${feed_dir}/2_opus.xml" +wget https://hackerpublicradio.org/hpr_ogg_rss.php -O "${feed_dir}/2_ogg.xml" +wget https://hackerpublicradio.org/hpr_rss.php -O "${feed_dir}/2_mp3.xml" +wget https://hackerpublicradio.org/hpr_total_opus_rss.php -O "${feed_dir}/f_opus.xml" +wget https://hackerpublicradio.org/hpr_total_ogg_rss.php -O "${feed_dir}/f_ogg.xml" +wget https://hackerpublicradio.org/hpr_total_rss.php -O "${feed_dir}/f_mp3.xml" +wget https://hackerpublicradio.org/rss-future.php -O "${feed_dir}/ff.xml" +wget https://hackerpublicradio.org/comments.rss -O "${feed_dir}/comments.xml" + +cd "${feed_dir}" + +for feed in *.xml +do + echo "Checking ${feed}" + xmllint --format "${feed}" >/dev/null 2>&1 + if [ "${?}" -ne "0" ] + then + echo "Error: The rss feed \"${feed}\" is not correct" + xmllint --format "${feed}" + exit 1 + fi +done diff --git a/workflow/export-jsons-stats.bash b/workflow/export-jsons-stats.bash new file mode 100755 index 0000000..a74d7bd --- /dev/null +++ b/workflow/export-jsons-stats.bash @@ -0,0 +1,8 @@ +#!/bin/bash + +# 6,21,36,51 * * * * /docker/users/hpr/userfiles/bin/export-jsons-stats.bash > /dev/null 2>&1 & + +net_rc="$HOME/userfiles/.netrc" +output_file="$HOME/hub.hackerpublicradio.org/public_html/stats.json" + +curl --silent --netrc-file ${net_rc} https://hub.hackerpublicradio.org/cms/stats.php --output "${output_file}" diff --git a/workflow/hpr-publish.bash b/workflow/hpr-publish.bash index b24bda0..4bd8c0a 100755 --- a/workflow/hpr-publish.bash +++ b/workflow/hpr-publish.bash @@ -2,16 +2,80 @@ # Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/ #============================================================ -git_dir="$HOME/tmp/hpr/hpr_generator/sourcecode" -if [ ! -d "${git_dir}/.git" ] +working_dir="$HOME/tmp/hpr/hpr_generator/sourcecode" +hpr_sql_rss="${working_dir}/hpr_sql_rss.xml" +previous_update_txt="${working_dir}/last_update.txt" + +if [ ! -d "${working_dir}/.git" ] then - git clone gitea@repo.anhonesthost.net:HPR/hpr_generator.git "${git_dir}" + mkdir --parents --verbose "${working_dir}" + git clone gitea@repo.anhonesthost.net:HPR/hpr_generator.git "${working_dir}" fi -cd "${git_dir}" - +cd "${working_dir}" git pull +function get_latest_update_time() { + if [ "$( curl --silent --netrc-file ${HOME}/.netrc --write-out '%{http_code}' https://hackerpublicradio.org/hpr.sql.rss --output "${hpr_sql_rss}" )" != 200 ] + then + echo "Could not get a list of the queue status from \"https://hackerpublicradio.org/hpr.sql.rss\"" + fi + + if [[ ! -s "${hpr_sql_rss}" || -z "${hpr_sql_rss}" ]] + then + echo "The \"hpr_sql_rss\" variable/file is missing." + exit + fi + if [ "$( file --brief --mime-type "${hpr_sql_rss}" | grep --count 'text/xml' )" -ne "1" ] + then + echo "The \"hpr_sql_rss\" variable has not a valid \"text/xml\" mime type." + exit + fi + xmllint --format "${hpr_sql_rss}" >/dev/null 2>&1 + if [ $? -ne 0 ] + then + echo "The file \"${hpr_sql_rss}\" is not valid xml." + exit + fi + + current_update_iso8601="$( \date --utc --date="$( xmlstarlet sel --text --template --match '/rss/channel/pubDate' --value-of '.' --nl "${hpr_sql_rss}" )" +%Y-%m-%dT%H:%M:%SZ )" + if [ -z "${current_update_iso8601}" ] + then + echo "The \"current_update_iso8601\" variable is missing." + exit + fi + + current_update_epoch="$( \date --utc --date="${current_update_iso8601}" +%s )" + if [ -z "${current_update_epoch}" ] + then + echo "The \"current_update_epoch\" variable/file is missing." + exit + fi + echo -e "Current update time is\t${current_update_iso8601} (${current_update_epoch})" + + if [ -s "${previous_update_txt}" ] + then + #echo "Found the last update file \"${previous_update_txt}\"" + previous_update_iso8601="$( \date --utc --date="$( cat "${previous_update_txt}" )" +%Y-%m-%dT%H:%M:%SZ )" + previous_update_epoch="$( \date --utc --date="$( cat "${previous_update_txt}" )" +%s )" + else + #echo "Did not find the last update file \"${previous_update_txt}\"" + previous_update_iso8601="" + previous_update_epoch="0" + fi + + echo -e "Previous update time is\t${previous_update_iso8601} (${previous_update_epoch})" + + echo "${current_update_iso8601}" > "${previous_update_txt}" + +} + +get_latest_update_time + + +# if [ "${current_update_epoch}" -eq "previous_update_epoch" +# exit + # ssh hpr -t "ls -al /home/hpr/www/hpr.sql;md5sum /home/hpr/www/hpr.sql" # ssh hpr -t "/home/hpr/bin/hpr_db_backup.bash" # ssh hpr -t "ls -al /home/hpr/www/hpr.sql;md5sum /home/hpr/www/hpr.sql" @@ -30,15 +94,30 @@ then exit 1 fi -rsync -av --partial --progress "${git_dir}/public_html/" hpr:hackerpublicradio.org/public_html -#rsync -av --partial --progress "${git_dir}/public_html/" hobbypublicradio.org:hobbypublicradio.org/ +cd "${working_dir}/public_html" -cd $HOME/sourcecode/hpr/hpr_hub/ -git pull -cd $HOME/sourcecode/hpr/hpr_hub/sql -split --hex-suffixes --lines=1000 --additional-suffix=.sql hpr.sql hpr-db-part- -cd $HOME/sourcecode/hpr/hpr_hub/ -git add $HOME/sourcecode/hpr/hpr_hub/sql/hpr*sql -git commit -m "$(\date -u +%Y-%m-%d_%H-%M-%SZ_%A ) database changed" -git push -#xdg-open https://hackerpublicradio.org/ +for feed in comments.rss +do + xmllint --format "${feed}" >/dev/null 2>&1 + if [ "${?}" -ne "0" ] + then + echo "Error: The rss feed \"${feed}\" is not correct" + xmllint --format "${feed}" + exit 1 + fi +done + +cd "${working_dir}" + +rsync -av --partial --progress "${working_dir}/public_html/" hpr:hackerpublicradio.org/public_html +#rsync -av --partial --progress "${working_dir}/public_html/" hobbypublicradio.org:hobbypublicradio.org/ + +# # # cd $HOME/sourcecode/hpr/hpr_hub/ +# # # git pull +# # # cd $HOME/sourcecode/hpr/hpr_hub/sql +# # # split --hex-suffixes --lines=1000 --additional-suffix=.sql hpr.sql hpr-db-part- +# # # cd $HOME/sourcecode/hpr/hpr_hub/ +# # # git add $HOME/sourcecode/hpr/hpr_hub/sql/hpr*sql +# # # git commit -m "$(\date -u +%Y-%m-%d_%H-%M-%SZ_%A ) database changed" +# # # git push +# # # #xdg-open https://hackerpublicradio.org/ diff --git a/workflow/hpr_db_backup.bash b/workflow/hpr_db_backup.bash index 4bb3733..8757109 100755 --- a/workflow/hpr_db_backup.bash +++ b/workflow/hpr_db_backup.bash @@ -2,6 +2,8 @@ # 5,20,35,50 * * * * $HOME/userfiles/sql/hpr_db_backup.bash >> $HOME/userfiles/sql/cron.log 2>&1 & +# https://hackerpublicradio.org/hpr.sql.rss + #TODO #add a rss feed with the latest updates. Linking to the changes on gittea. # run that every 5 minutes and then if there is a change sleep 5 and confirm there has been no change since. diff --git a/workflow/process_episode.bash b/workflow/process_episode.bash index 424b606..1763420 100755 --- a/workflow/process_episode.bash +++ b/workflow/process_episode.bash @@ -719,7 +719,6 @@ function get_working_dir() { } - ################################################# # Once the working_dir is known, set the other variables