Compare commits
	
		
			2 Commits
		
	
	
		
			d19fe2e4bf
			...
			2e7ae52cf1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					2e7ae52cf1 | ||
| 
						 | 
					782f501c2b | 
							
								
								
									
										17
									
								
								Community_News/hosts_in_year.sqlite.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Community_News/hosts_in_year.sqlite.sql
									
									
									
									
									
										Normal 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)
 | 
			
		||||
							
								
								
									
										53
									
								
								Community_News/hosts_list.tpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Community_News/hosts_list.tpl
									
									
									
									
									
										Normal 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
 | 
			
		||||
-%]
 | 
			
		||||
@@ -159,8 +159,11 @@ Options( \%options );
 | 
			
		||||
#
 | 
			
		||||
# Default help is just the USAGE section
 | 
			
		||||
#
 | 
			
		||||
pod2usage( -msg => "$PROG version $VERSION\n", -verbose => 0, -exitval => 1 )
 | 
			
		||||
    if ( $options{'help'} );
 | 
			
		||||
pod2usage(
 | 
			
		||||
    -msg => "$PROG version $VERSION\n",
 | 
			
		||||
    -verbose => 0,
 | 
			
		||||
    -exitval => 1
 | 
			
		||||
) if ( $options{'help'} );
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Full documentation if requested with -documentation or -man
 | 
			
		||||
 
 | 
			
		||||
@@ -1,38 +0,0 @@
 | 
			
		||||
2021-10-01,2021-10-30 14:00:00
 | 
			
		||||
2022-06-01,2022-07-02 14:00:00
 | 
			
		||||
2022-07-01,2022-07-30 14:00:00
 | 
			
		||||
2022-08-01,2022-09-03 14:00:00
 | 
			
		||||
2022-09-01,2022-10-01 14:00:00
 | 
			
		||||
2022-10-01,2022-11-05 14:00:00
 | 
			
		||||
2022-11-01,2022-12-03 15:00:00
 | 
			
		||||
2022-12-01,2022-12-27 15:00:00
 | 
			
		||||
2023-01-01,2023-02-04 15:00:00
 | 
			
		||||
2023-02-01,2023-03-04 15:00:00
 | 
			
		||||
2023-03-01,2023-04-01 15:00:00
 | 
			
		||||
2023-04-01,2023-04-29 15:00:00
 | 
			
		||||
2023-05-01,2023-06-03 15:00:00
 | 
			
		||||
2023-07-01,2023-08-05 15:00:00
 | 
			
		||||
2023-08-01,2023-09-02 15:00:00
 | 
			
		||||
2023-09-01,2023-09-30 15:00:00
 | 
			
		||||
2023-10-01,2023-11-04 15:00:00
 | 
			
		||||
2023-11-01,2023-12-02 15:00:00
 | 
			
		||||
2023-12-01,2023-12-30 15:00:00
 | 
			
		||||
2024-01-01,2024-02-04 15:00:00
 | 
			
		||||
2024-02-01,2024-03-02 15:00:00
 | 
			
		||||
2024-03-01,2024-03-30 15:00:00
 | 
			
		||||
2024-05-01,2024-06-02 13:00:00
 | 
			
		||||
2024-06-01,2024-06-28 15:00:00
 | 
			
		||||
2024-07-01,2024-08-02 15:00:00
 | 
			
		||||
2024-08-01,2024-08-29 15:00:00
 | 
			
		||||
2024-09-01,2024-10-04 15:00:00
 | 
			
		||||
2024-10-01,2024-11-01 15:00:00
 | 
			
		||||
2024-11-01,2024-11-29 15:00:00
 | 
			
		||||
2024-12-01,2025-01-03 15:00:00
 | 
			
		||||
2025-01-01,2025-01-31 15:00:00
 | 
			
		||||
2025-02-01,2025-02-28 16:00:00
 | 
			
		||||
2025-03-01,2025-04-04 16:00:00
 | 
			
		||||
2025-04-01,2025-05-02 15:00:00
 | 
			
		||||
2025-05-01,2025-05-30 15:00:00
 | 
			
		||||
2025-06-01,2025-07-04 15:00:00
 | 
			
		||||
2025-07-01,2025-08-01 15:00:00
 | 
			
		||||
2025-08-01,2025-08-29 15:00:00
 | 
			
		||||
							
								
								
									
										114
									
								
								Community_News/thanks_to_hosts
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										114
									
								
								Community_News/thanks_to_hosts
									
									
									
									
									
										Executable 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
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user