Compare commits
No commits in common. "f11cea952837e512e52e7e3f437c56d39ca93edb" and "01422d0bd7d619e0e6a9b5c4116ea6af6e53b867" have entirely different histories.
f11cea9528
...
01422d0bd7
@ -1,39 +0,0 @@
|
|||||||
[%# ==========================================================================
|
|
||||||
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
|
|
||||||
thus:
|
|
||||||
year="2022" # or whatever
|
|
||||||
./query2tt2 -query=$HOME/HPR/Community_News/hosts_showcount.sql \
|
|
||||||
-conf=$HOME/HPR/.hpr_livedb.cfg \
|
|
||||||
-dbargs "${year}-01-01" -dbargs "${year}-12-31" -def year=${year} \
|
|
||||||
-template=$HOME/HPR/Community_News/hosts_list.tpl \
|
|
||||||
> $HOME/HPR/Community_News/hosts_showcount_${year}.html
|
|
||||||
|
|
||||||
[We can't use the planned pure TT2 version since Template::Plugin::DBI
|
|
||||||
can't run over the SSH tunnel.]
|
|
||||||
|
|
||||||
2023-10-30 The correspondent URL has changed with the static site, and needs
|
|
||||||
the hostid to be zero-padded.
|
|
||||||
========================================================================== -%]
|
|
||||||
[%- 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
|
|
||||||
-%]
|
|
@ -1,15 +0,0 @@
|
|||||||
--
|
|
||||||
-- 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 h.host
|
|
@ -21,7 +21,7 @@
|
|||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.4
|
# VERSION: 0.0.4
|
||||||
# CREATED: 2015-07-11 15:53:01
|
# CREATED: 2015-07-11 15:53:01
|
||||||
# REVISION: 2025-05-09 14:13:17
|
# REVISION: 2025-05-06 21:12:08
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -136,10 +136,8 @@ else {
|
|||||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||||
|
|
||||||
#
|
#
|
||||||
# Count placeholders in the query and the arguments provided. First remove all
|
# Count placeholders in the query and the arguments provided
|
||||||
# comments which may contain '?' characters, then count any that are left.
|
|
||||||
#
|
#
|
||||||
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
|
||||||
$pcount = grep {/\?/} split( '', $query );
|
$pcount = grep {/\?/} split( '', $query );
|
||||||
$acount = scalar(@dbargs);
|
$acount = scalar(@dbargs);
|
||||||
|
|
||||||
@ -359,8 +357,8 @@ sub _dbargs {
|
|||||||
|
|
||||||
my @args;
|
my @args;
|
||||||
|
|
||||||
if ( defined( $opts->{dbarg} ) ) {
|
if ( defined( $opts->{dbargs} ) ) {
|
||||||
@args = @{ $opts->{dbarg} };
|
@args = @{ $opts->{dbargs} };
|
||||||
}
|
}
|
||||||
|
|
||||||
return (@args);
|
return (@args);
|
||||||
@ -381,7 +379,7 @@ sub Options {
|
|||||||
|
|
||||||
my @options = (
|
my @options = (
|
||||||
"help", "documentation|man", "debug=i", "config=s",
|
"help", "documentation|man", "debug=i", "config=s",
|
||||||
"output=s", "query=s", "dbarg=s@", "header!",
|
"output=s", "query=s", "dbargs=s@", "header!",
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( !GetOptions( $optref, @options ) ) {
|
if ( !GetOptions( $optref, @options ) ) {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.3
|
# VERSION: 0.0.3
|
||||||
# CREATED: 2021-06-18 13:24:49
|
# CREATED: 2021-06-18 13:24:49
|
||||||
# REVISION: 2025-05-09 14:13:27
|
# REVISION: 2025-05-07 09:50:34
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -132,10 +132,8 @@ else {
|
|||||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||||
|
|
||||||
#
|
#
|
||||||
# Count placeholders in the query and the arguments provided. First remove all
|
# Count placeholders in the query and the arguments provided
|
||||||
# comments which may contain '?' characters, then count any that are left.
|
|
||||||
#
|
#
|
||||||
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
|
||||||
$pcount = grep {/\?/} split( '', $query );
|
$pcount = grep {/\?/} split( '', $query );
|
||||||
$acount = scalar(@dbargs);
|
$acount = scalar(@dbargs);
|
||||||
|
|
||||||
@ -214,9 +212,9 @@ catch ($e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Prepare for JSON, forcing object key sorting (expensive), and prettification
|
# Prepare for JSON, forcing object key sorting (expensive)
|
||||||
#
|
#
|
||||||
$json = JSON->new->utf8->canonical->pretty;
|
$json = JSON->new->utf8->canonical;
|
||||||
|
|
||||||
#
|
#
|
||||||
# Grab everything as an arrayref of hashrefs
|
# Grab everything as an arrayref of hashrefs
|
||||||
@ -343,8 +341,8 @@ sub _dbargs {
|
|||||||
|
|
||||||
my @args;
|
my @args;
|
||||||
|
|
||||||
if ( defined( $opts->{dbarg} ) ) {
|
if ( defined( $opts->{dbargs} ) ) {
|
||||||
@args = @{ $opts->{dbarg} };
|
@args = @{ $opts->{dbargs} };
|
||||||
}
|
}
|
||||||
|
|
||||||
return (@args);
|
return (@args);
|
||||||
@ -393,7 +391,7 @@ This documentation refers to query2json version 0.0.3
|
|||||||
=head1 USAGE
|
=head1 USAGE
|
||||||
|
|
||||||
query2json [-help] [-documentation|-man] [-debug=N] [-config=FILE]
|
query2json [-help] [-documentation|-man] [-debug=N] [-config=FILE]
|
||||||
[-query=FILE] [-output=FILE] [QUERY]
|
[-query=FILE] [-output=FILE] [-[no]header] [QUERY]
|
||||||
|
|
||||||
=head1 OPTIONS
|
=head1 OPTIONS
|
||||||
|
|
||||||
@ -463,6 +461,11 @@ these placeholders can be passed to the script through the B<-dbarg=ARG>
|
|||||||
option. The option can be repeated as many times as required and the order of
|
option. The option can be repeated as many times as required and the order of
|
||||||
B<ARG> values is preserved.
|
B<ARG> values is preserved.
|
||||||
|
|
||||||
|
=item B<-[no-]header>
|
||||||
|
|
||||||
|
This option allows a header to be added to the CSV output with the names of
|
||||||
|
the database columns in CSV format. By default this is not produced.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.8
|
# VERSION: 0.0.8
|
||||||
# CREATED: 2021-06-18 13:24:49
|
# CREATED: 2021-06-18 13:24:49
|
||||||
# REVISION: 2025-05-09 14:13:04
|
# REVISION: 2025-05-06 16:39:25
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -119,6 +119,7 @@ pod2usage(
|
|||||||
-noperldoc => 0,
|
-noperldoc => 0,
|
||||||
) if ( $options{'documentation'} );
|
) if ( $options{'documentation'} );
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Collect options
|
# Collect options
|
||||||
#
|
#
|
||||||
@ -163,16 +164,11 @@ else {
|
|||||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||||
|
|
||||||
#
|
#
|
||||||
# Count placeholders in the query and the arguments provided. First remove all
|
# Count placeholders in the query and the arguments provided
|
||||||
# comments which may contain '?' characters, then count any that are left.
|
|
||||||
#
|
#
|
||||||
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
|
||||||
$pcount = grep {/\?/} split( '', $query );
|
$pcount = grep {/\?/} split( '', $query );
|
||||||
$acount = scalar(@dbargs);
|
$acount = scalar(@dbargs);
|
||||||
|
|
||||||
#
|
|
||||||
# Check the placeholder and argument counts are the same
|
|
||||||
#
|
|
||||||
if ( $pcount ne $acount) {
|
if ( $pcount ne $acount) {
|
||||||
say STDERR "Query placeholder vs argument mismatch";
|
say STDERR "Query placeholder vs argument mismatch";
|
||||||
say STDERR "Placeholders = $pcount, Arguments = $acount";
|
say STDERR "Placeholders = $pcount, Arguments = $acount";
|
||||||
@ -419,8 +415,8 @@ sub _dbargs {
|
|||||||
|
|
||||||
my @args;
|
my @args;
|
||||||
|
|
||||||
if ( defined( $opts->{dbarg} ) ) {
|
if ( defined( $opts->{dbargs} ) ) {
|
||||||
@args = @{ $opts->{dbarg} };
|
@args = @{ $opts->{dbargs} };
|
||||||
}
|
}
|
||||||
|
|
||||||
return (@args);
|
return (@args);
|
||||||
@ -468,7 +464,7 @@ sub Options {
|
|||||||
"help", "documentation|man",
|
"help", "documentation|man",
|
||||||
"debug=i", "config=s",
|
"debug=i", "config=s",
|
||||||
"output=s", "query=s",
|
"output=s", "query=s",
|
||||||
"template=s", "dbarg=s@",
|
"template=s", "dbargs=s@",
|
||||||
"define=s%",
|
"define=s%",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user