dat update and minor format changes

This commit is contained in:
2025-10-20 15:37:24 +02:00
5 changed files with 240 additions and 2 deletions

View File

@@ -0,0 +1,51 @@
# Thanking hosts at the end of the year
## Introduction
Every year, in the last Community News recording (for December) it has been the
norm to list all of the hosts who have contributed. A list of host names is
assembled for this purpose, included in the notes and read out by the
volunteers.
## Method
A Bash script exists, called `thanks_to_hosts`, which manages the generation of
the list of hosts. The end product is a piece of HTML for insertion into the
notes.
The script is invoked simply by typing:
```
thanks_to_hosts
```
By default, the script uses the current year when generating the list of hosts.
If, as may happen, the list is being generated in the next year, then a 4-digit
year can be given in as an argument.
### Items required to run
The `thanks_to_hosts` script requires a number of tools and files to run:
- `query2tt2` - this is a Perl script which performs a database query and hands
the results to Template Toolkit template.
- `hpr.db` - a SQLite database which contains a copy of the live HPR database.
This needs to have been refreshed in the recent past.
- `.hpr_sqlite.cfg` - the configuration file for `query2tt2` to indicate what
type of database is being used and where to find it.
- `hosts_in_year.sqlite.sql` - a file containing the query used (using SQLite
syntax)
- `hosts_list.tpl` - the template which will be used to generate HTML
### Output file
Running the script `thanks_to_hosts`, if successful, will result in the
generation of a file called `hosts_in_year_${YEAR}.html`, where `${YEAR}` is
replaced by the default or explicit year. The script will report the name of
this file for convenience.
<!--
vim: syntax=markdown:ts=8:sw=4:ai:et:tw=78:fo=tcqn:fdm=marker:com+=fb\:-
-->

View File

@@ -0,0 +1,17 @@
--
-- hosts_in_year.sqlite.sql 2025-10-06
--
-- Query for use with 'query2tt2' to generate a list of hosts who contributed
-- shows in a particular year. Designed to be used with the 'hosts_list.tpl'
-- template.
-- The two '?' placeholders in the query are to be filled with 'YYYY-01-01'
-- for the start of the year and 'YYYY-12-31'. The values can be passed using
-- the '-dbargs' option to 'query2tt2'.
--
SELECT DISTINCT
printf('%04d',h.hostid) AS hostid, h.host AS hostname
FROM eps e
JOIN hosts h ON e.hostid = h.hostid
WHERE e.date BETWEEN ? AND ?
AND title != 'Reserved'
ORDER BY lower(h.host)

View File

@@ -0,0 +1,53 @@
[%# ==========================================================================
This is the TT2 file for making a list of hosts contributing to HPR in the
current year which is run in conjunction with 'query2tt2'. It's invoked
by using the Bash script 'thanks_to_hosts'.
[We can't use the planned pure TT2 version since Template::Plugin::DBI
can't run over the SSH tunnel.]
The 'query2tt2' script needs a configuration file '.hpr_sqlite.cfg,' though this
is the default.
The file 'hosts_in_year.sqlite.sql' is used to generate the 'result' hash
which is used by this template. The query needs to be given the first and last
dates of the year.
This template uses the variable 'year' which can be provided to 'query2tt2'
using the option '-def year="$year"' or similar. If not provided the default
value is the current year.
The 'result' hash is sorted by host name. The loop which writes the output
generates links to the HPR website, with 8 per list element
Changes:
-------
2023-10-30: The correspondent URL has changed with the static site, and needs
the hostid to be zero-padded.
2025-01-01: We now use a copy of the live database, built from the HPR server
and available as https://www.hackerpublicradio.org/hpr.sql. This is
a MySQL/MariaDB dump which can be used to create a MariaDB or a SQLite copy.
See the script collect_HPR_database for how the SQLite version is created.
========================================================================== -%]
[%- USE date -%]
[%- DEFAULT
year = date.format(date.now,'%Y','UTC')
-%]
<h3>Thanks to all [% result.size %] HPR contributors in [% year %]!</h3>
[% limit = 8 -%]
[% count = 0 -%]
<p><ul><li>
[% FOREACH h = result -%]
<a href="https://hackerpublicradio.org/correspondents/[% h.hostid %].html">[% h.hostname %]</a>
[%- IF loop.count mod limit == 0 || loop.count == result.size -%].[% ELSE %],[% END %]
[% count = count + 1 -%]
[% IF count == limit -%]
[% count = 0 -%]
</li><li>
[% END -%]
[% END -%]
</li></ul></p>
[%#
# vim: syntax=tt2:ts=8:sw=4:ai:et:tw=78:fo=tcrqn21:fdm=marker
-%]

View File

@@ -159,8 +159,11 @@ Options( \%options );
# #
# Default help is just the USAGE section # Default help is just the USAGE section
# #
pod2usage( -msg => "$PROG version $VERSION\n", -verbose => 0, -exitval => 1 ) pod2usage(
if ( $options{'help'} ); -msg => "$PROG version $VERSION\n",
-verbose => 0,
-exitval => 1
) if ( $options{'help'} );
# #
# Full documentation if requested with -documentation or -man # Full documentation if requested with -documentation or -man

114
Community_News/thanks_to_hosts Executable file
View File

@@ -0,0 +1,114 @@
#!/bin/bash -
#===============================================================================
#
# FILE: thanks_to_hosts
#
# USAGE: ./thanks_to_hosts [year]
#
# DESCRIPTION: Generates HTML to be added to the Community News at the end of
# the year in order to thank hosts contributing shows in that
# year.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
# VERSION: 0.0.1
# CREATED: 2025-10-06 16:38:42
# REVISION: 2025-10-06 18:06:12
#
#===============================================================================
set -o nounset # Treat unset variables as an error
#
# Process the year, either as an argument or as a default (the current year)
#
YEAR="${1:-}"
if [[ -z $YEAR ]]; then
YEAR="$(date +%Y)"
else
if ! [[ $YEAR =~ ^[0-9]{4}$ ]]; then
echo "Invalid year: '$YEAR'"
exit 1
fi
fi
#
# Various constants
#
# Uncomment the first form and comment out the second form unless 'query2tt2'
# is in your path. It or a link to the script will need to be in the current
# directory.
#
# DBQUERY='./query2tt2'
DBQUERY="$(command -v query2tt2)"
#
# Files expected to be in the current directory, or which will be written
# there. These could be given full absolute paths if desired.
#
DB='hpr.db'
CONFIG='.hpr_sqlite.cfg'
QUERY='hosts_in_year.sqlite.sql'
TEMPLATE='hosts_list.tpl'
OUTPUT="hosts_in_year_${YEAR}.html"
# [Nothing should need editing below here]
#
# Start and end of the year
#
YRSTART="${YEAR}-01-01"
YREND="${YEAR}-12-31"
#
# Sanity checks
#
[ -e "$DBQUERY" ] || {
echo "Unable to find '$DBQUERY'"
exit 1
}
[ -e $DB ] || {
echo "Unable to find '$DB'"
exit 1
}
[ -e $CONFIG ] || {
echo "Unable to find '$CONFIG'"
exit 1
}
[ -e $QUERY ] || {
echo "Unable to find '$QUERY'"
exit 1
}
[ -e $TEMPLATE ] || {
echo "Unable to find '$TEMPLATE'"
exit 1
}
#
# Query the SQLite database
#
$DBQUERY \
-config=$CONFIG \
-query=$QUERY \
-template=$TEMPLATE \
-dbarg "$YRSTART" \
-dbarg "$YREND" \
-def "year=${YEAR}" \
-out="$OUTPUT"
RES=$?
#
# Deal with failures
#
if [[ $RES -eq 0 ]]; then
echo "HTML written to $OUTPUT"
else
echo "Problem generating HTML"
fi
exit $RES
# vim: syntax=sh:ts=8:sw=4:ai:et:tw=78:fo=tcrqn21