Compare commits
23 Commits
01422d0bd7
...
main
Author | SHA1 | Date | |
---|---|---|---|
89b51b4406 | |||
274dfb7dba | |||
31986b3ea6 | |||
4f5cbb24be | |||
b816d85019 | |||
24e36b945a | |||
dd97a672aa | |||
6f3c6c2596 | |||
|
0fc70df8ac | ||
1dd1c8c100 | |||
|
b514cfa380 | ||
b84ff7a4c8 | |||
e8c203debf | |||
6150943cb3 | |||
946fb47508 | |||
d7bee0be56 | |||
35305a5c45 | |||
12d76f8a52 | |||
240ece066b | |||
|
f11cea9528 | ||
|
fdd0823f93 | ||
62071280a5 | |||
|
bf8f6db45c |
62
Containerfile
Normal file
62
Containerfile
Normal file
@@ -0,0 +1,62 @@
|
||||
FROM perl:5.40.1 As base
|
||||
|
||||
LABEL author="sgoti" \
|
||||
email="lyunpaw@gmail.com" \
|
||||
project="Hacker Public Radio" \
|
||||
forge="https://repo.anhonesthost.net/HPR"
|
||||
|
||||
ARG unprivilegedUser="janitor"
|
||||
|
||||
RUN apt update && apt upgrade --yes;
|
||||
|
||||
RUN apt install --no-install-recommends sqlite3 git --yes \
|
||||
&& rm --recursive --force /var/lib/apt/lists/*;
|
||||
|
||||
RUN mkdir --verbose --parent /opt/hpr /tmp/hpr;
|
||||
|
||||
RUN groupadd --system ${unprivilegedUser} \
|
||||
&& useradd --system --no-log-init --gid ${unprivilegedUser} ${unprivilegedUser};
|
||||
|
||||
RUN chown --recursive ${unprivilegedUser}:${unprivilegedUser} /opt/hpr \
|
||||
&& chown --recursive ${unprivilegedUser}:${unprivilegedUser} /tmp/hpr;
|
||||
|
||||
#Bill of particulars.
|
||||
|
||||
##Meta::CPAN (Comprehensive Perl Archive Network)
|
||||
RUN cpanm Config::General \
|
||||
DBD::SQLite \
|
||||
DBI \
|
||||
Data::Dumper \
|
||||
Date::Calc \
|
||||
Date::Parse \
|
||||
DateTime \
|
||||
DateTime::Duration \
|
||||
DateTime::Format::Duration \
|
||||
DateTime::TimeZone \
|
||||
HTML::Entities \
|
||||
JSON \
|
||||
Template \
|
||||
Template::Filters;
|
||||
|
||||
##Included perl core modules (standard library).
|
||||
##Carp
|
||||
##Cwd
|
||||
##Getopt::Long
|
||||
##Pod::Usage
|
||||
##File::Copy
|
||||
|
||||
USER ${unprivilegedUser}
|
||||
|
||||
WORKDIR /opt/hpr
|
||||
|
||||
RUN git clone https://repo.anhonesthost.net/HPR/hpr-tools.git \
|
||||
&& git clone https://repo.anhonesthost.net/HPR/hpr_hub.git \
|
||||
&& git clone https://repo.anhonesthost.net/HPR/hpr_generator.git \
|
||||
&& git clone https://repo.anhonesthost.net/HPR/hpr_documentation.git;
|
||||
|
||||
WORKDIR /opt/hpr/hpr-tools/Community_News/
|
||||
RUN ln --symbolic /opt/hpr/hpr_generator/utils/mysql2sqlite /opt/hpr/hpr-tools/Community_News/mysql2sqlite;
|
||||
RUN ./collect_HPR_database;
|
||||
|
||||
CMD bash;
|
||||
|
39
Database/hosts_list.tpl
Normal file
39
Database/hosts_list.tpl
Normal file
@@ -0,0 +1,39 @@
|
||||
[%# ==========================================================================
|
||||
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
|
||||
-%]
|
15
Database/hosts_showcount.sqlite.sql
Normal file
15
Database/hosts_showcount.sqlite.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
--
|
||||
-- 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
|
@@ -19,9 +19,9 @@
|
||||
# BUGS: ---
|
||||
# NOTES: ---
|
||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||
# VERSION: 0.0.4
|
||||
# VERSION: 0.0.5
|
||||
# CREATED: 2015-07-11 15:53:01
|
||||
# REVISION: 2025-05-06 21:12:08
|
||||
# REVISION: 2025-05-25 18:26:13
|
||||
#
|
||||
#===============================================================================
|
||||
|
||||
@@ -46,7 +46,7 @@ use Data::Dumper;
|
||||
#
|
||||
# Version number (manually incremented)
|
||||
#
|
||||
our $VERSION = '0.0.4';
|
||||
our $VERSION = '0.0.5';
|
||||
|
||||
#
|
||||
# Script name
|
||||
@@ -136,8 +136,15 @@ else {
|
||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||
|
||||
#
|
||||
# Count placeholders in the query and the arguments provided
|
||||
# Strip SQL comments
|
||||
#
|
||||
$query = strip_sql_comments($query);
|
||||
|
||||
#
|
||||
# Count placeholders in the query and the arguments provided. First remove all
|
||||
# comments which may contain '?' characters, then count any that are left.
|
||||
#
|
||||
#$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
||||
$pcount = grep {/\?/} split( '', $query );
|
||||
$acount = scalar(@dbargs);
|
||||
|
||||
@@ -171,7 +178,7 @@ else {
|
||||
# Load database configuration data; allow environment variables
|
||||
#-------------------------------------------------------------------------------
|
||||
my $conf = Config::General->new(
|
||||
-ConfigFile => $configfile,
|
||||
-ConfigFile => $cfgfile,
|
||||
-InterPolateVars => 1,
|
||||
-InterPolateEnv => 1,
|
||||
-ExtendedAccess => 1
|
||||
@@ -179,7 +186,7 @@ my $conf = Config::General->new(
|
||||
my %config = $conf->getall();
|
||||
|
||||
#
|
||||
# Set defaults
|
||||
# Set defaults in case values have been omitted
|
||||
#
|
||||
$config{database}->{dbtype} //= 'SQLite';
|
||||
$config{database}->{host} //= '127.0.0.1';
|
||||
@@ -261,13 +268,13 @@ exit;
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub db_connect {
|
||||
sub db_connect { #{{{
|
||||
my ($cfg) = @_;
|
||||
|
||||
my ( $dbh, $dbtype, $dbname );
|
||||
|
||||
$dbtype = $config{database}->{dbtype};
|
||||
$dbname = $config{database}->{name};
|
||||
$dbtype = $cfg->{database}->{dbtype};
|
||||
$dbname = $cfg->{database}->{name};
|
||||
die "Database name is mandatory\n" unless $dbname;
|
||||
|
||||
#
|
||||
@@ -278,6 +285,7 @@ sub db_connect {
|
||||
# The name for the SQLite driver is 'DBD:SQLite'
|
||||
#
|
||||
$dbtype = 'SQLite';
|
||||
_debug( $DEBUG >= 3, '$dbtype: ' . $dbtype, '$dbname: ' . $dbname );
|
||||
|
||||
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
||||
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
||||
@@ -289,10 +297,10 @@ sub db_connect {
|
||||
#
|
||||
$dbtype = 'mysql';
|
||||
|
||||
my $dbhost = $config{database}->{host};
|
||||
my $dbport = $config{database}->{port};
|
||||
my $dbuser = $config{database}->{user};
|
||||
my $dbpwd = $config{database}->{password};
|
||||
my $dbhost = $cfg->{database}->{host};
|
||||
my $dbport = $cfg->{database}->{port};
|
||||
my $dbuser = $cfg->{database}->{user};
|
||||
my $dbpwd = $cfg->{database}->{password};
|
||||
|
||||
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
||||
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
||||
@@ -318,28 +326,68 @@ sub db_connect {
|
||||
}
|
||||
|
||||
return $dbh;
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: strip_sql_comments
|
||||
# PURPOSE: Given a query as a scalar, strips all SQL comments
|
||||
# PARAMETERS: $query string containing a query
|
||||
# RETURNS: Stripped string
|
||||
# DESCRIPTION: Two types of comments might exist in the query: the C-style
|
||||
# and the SQL style. The string is treated as a single string
|
||||
# even though it's multi-line, and any C-style comments are
|
||||
# removed. Then the string is treated as multi-line and each
|
||||
# line is scanned for SQL comments (which end at the end of the
|
||||
# line), and these are stripped. Blank lines are skipped too to
|
||||
# compress the output a little.
|
||||
# THROWS: No exceptions
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub strip_sql_comments { #{{{
|
||||
my ($query) = @_;
|
||||
|
||||
my $result;
|
||||
|
||||
#
|
||||
# Strip C-style comments
|
||||
#
|
||||
$query =~ s/\/\*.*?\*\///sg;
|
||||
|
||||
#
|
||||
# Strip SQL line-oriented comments
|
||||
#
|
||||
foreach my $line (split(/\n/,$query)) {
|
||||
next if $line =~ /^\s*$/;
|
||||
$line =~ s/--.*$//;
|
||||
$result .= "$line\n";
|
||||
}
|
||||
|
||||
return $result;
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: _debug
|
||||
# PURPOSE: Prints debug reports
|
||||
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
||||
# $message Message to print
|
||||
# @messages Messages to print
|
||||
# RETURNS: Nothing
|
||||
# DESCRIPTION: Outputs a message if $active is true. It removes any trailing
|
||||
# newline and then adds one in the 'print' to the caller doesn't
|
||||
# have to bother. Prepends the message with 'D> ' to show it's
|
||||
# DESCRIPTION: Outputs messages if $active is true. It removes any trailing
|
||||
# newlines and then adds one to each line so the caller doesn't
|
||||
# have to bother. Prepends 'D> ' to each message to show it's
|
||||
# a debug message.
|
||||
# THROWS: No exceptions
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub _debug {
|
||||
my ( $active, $message ) = @_;
|
||||
sub _debug { #{{{
|
||||
my ( $active, @messages ) = @_;
|
||||
|
||||
chomp($message);
|
||||
print STDERR "D> $message\n" if $active;
|
||||
}
|
||||
if ($active) {
|
||||
chomp(@messages);
|
||||
say STDERR "D> ", join( "\nD> ", @messages );
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: _dbargs
|
||||
@@ -352,17 +400,17 @@ sub _debug {
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub _dbargs {
|
||||
sub _dbargs { #{{{
|
||||
my ($opts) = @_;
|
||||
|
||||
my @args;
|
||||
|
||||
if ( defined( $opts->{dbargs} ) ) {
|
||||
@args = @{ $opts->{dbargs} };
|
||||
if ( defined( $opts->{dbarg} ) ) {
|
||||
@args = @{ $opts->{dbarg} };
|
||||
}
|
||||
|
||||
return (@args);
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: Options
|
||||
@@ -374,12 +422,12 @@ sub _dbargs {
|
||||
# COMMENTS: none
|
||||
# SEE ALSO: n/a
|
||||
#===============================================================================
|
||||
sub Options {
|
||||
sub Options { #{{{
|
||||
my ($optref) = @_;
|
||||
|
||||
my @options = (
|
||||
"help", "documentation|man", "debug=i", "config=s",
|
||||
"output=s", "query=s", "dbargs=s@", "header!",
|
||||
"output=s", "query=s", "dbarg=s@", "header!",
|
||||
);
|
||||
|
||||
if ( !GetOptions( $optref, @options ) ) {
|
||||
@@ -387,7 +435,7 @@ sub Options {
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} #}}}
|
||||
|
||||
__END__
|
||||
|
||||
@@ -402,7 +450,7 @@ query2csv - A script for generating CSV from database query
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
This documentation refers to query2csv version 0.0.4
|
||||
This documentation refers to query2csv version 0.0.5
|
||||
|
||||
=head1 USAGE
|
||||
|
||||
|
@@ -18,9 +18,9 @@
|
||||
# BUGS: ---
|
||||
# NOTES: ---
|
||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||
# VERSION: 0.0.3
|
||||
# VERSION: 0.0.4
|
||||
# CREATED: 2021-06-18 13:24:49
|
||||
# REVISION: 2025-05-07 09:50:34
|
||||
# REVISION: 2025-05-25 18:48:59
|
||||
#
|
||||
#===============================================================================
|
||||
|
||||
@@ -45,7 +45,7 @@ use Data::Dumper;
|
||||
#
|
||||
# Version number (manually incremented)
|
||||
#
|
||||
our $VERSION = '0.0.3';
|
||||
our $VERSION = '0.0.4';
|
||||
|
||||
#
|
||||
# Script name
|
||||
@@ -132,8 +132,15 @@ else {
|
||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||
|
||||
#
|
||||
# Count placeholders in the query and the arguments provided
|
||||
# Strip SQL comments
|
||||
#
|
||||
$query = strip_sql_comments($query);
|
||||
|
||||
#
|
||||
# Count placeholders in the query and the arguments provided. First remove all
|
||||
# comments which may contain '?' characters, then count any that are left.
|
||||
#
|
||||
#$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
||||
$pcount = grep {/\?/} split( '', $query );
|
||||
$acount = scalar(@dbargs);
|
||||
|
||||
@@ -175,7 +182,7 @@ my $conf = Config::General->new(
|
||||
my %config = $conf->getall();
|
||||
|
||||
#
|
||||
# Set defaults
|
||||
# Set defaults in case values have been omitted
|
||||
#
|
||||
$config{database}->{dbtype} //= 'SQLite';
|
||||
$config{database}->{host} //= '127.0.0.1';
|
||||
@@ -212,9 +219,9 @@ catch ($e) {
|
||||
}
|
||||
|
||||
#
|
||||
# Prepare for JSON, forcing object key sorting (expensive)
|
||||
# Prepare for JSON, forcing object key sorting (expensive), and prettification
|
||||
#
|
||||
$json = JSON->new->utf8->canonical;
|
||||
$json = JSON->new->utf8->canonical->pretty;
|
||||
|
||||
#
|
||||
# Grab everything as an arrayref of hashrefs
|
||||
@@ -245,13 +252,13 @@ exit;
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub db_connect {
|
||||
sub db_connect { #{{{
|
||||
my ($cfg) = @_;
|
||||
|
||||
my ( $dbh, $dbtype, $dbname );
|
||||
|
||||
$dbtype = $config{database}->{dbtype};
|
||||
$dbname = $config{database}->{name};
|
||||
$dbtype = $cfg->{database}->{dbtype};
|
||||
$dbname = $cfg->{database}->{name};
|
||||
die "Database name is mandatory\n" unless $dbname;
|
||||
|
||||
#
|
||||
@@ -262,6 +269,7 @@ sub db_connect {
|
||||
# The name for the SQLite driver is 'DBD:SQLite'
|
||||
#
|
||||
$dbtype = 'SQLite';
|
||||
_debug( $DEBUG >= 3, '$dbtype: ' . $dbtype, '$dbname: ' . $dbname );
|
||||
|
||||
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
||||
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
||||
@@ -273,10 +281,10 @@ sub db_connect {
|
||||
#
|
||||
$dbtype = 'mysql';
|
||||
|
||||
my $dbhost = $config{database}->{host};
|
||||
my $dbport = $config{database}->{port};
|
||||
my $dbuser = $config{database}->{user};
|
||||
my $dbpwd = $config{database}->{password};
|
||||
my $dbhost = $cfg->{database}->{host};
|
||||
my $dbport = $cfg->{database}->{port};
|
||||
my $dbuser = $cfg->{database}->{user};
|
||||
my $dbpwd = $cfg->{database}->{password};
|
||||
|
||||
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
||||
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
||||
@@ -302,28 +310,68 @@ sub db_connect {
|
||||
}
|
||||
|
||||
return $dbh;
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: strip_sql_comments
|
||||
# PURPOSE: Given a query as a scalar, strips all SQL comments
|
||||
# PARAMETERS: $query string containing a query
|
||||
# RETURNS: Stripped string
|
||||
# DESCRIPTION: Two types of comments might exist in the query: the C-style
|
||||
# and the SQL style. The string is treated as a single string
|
||||
# even though it's multi-line, and any C-style comments are
|
||||
# removed. Then the string is treated as multi-line and each
|
||||
# line is scanned for SQL comments (which end at the end of the
|
||||
# line), and these are stripped. Blank lines are skipped too to
|
||||
# compress the output a little.
|
||||
# THROWS: No exceptions
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub strip_sql_comments { #{{{
|
||||
my ($query) = @_;
|
||||
|
||||
my $result;
|
||||
|
||||
#
|
||||
# Strip C-style comments
|
||||
#
|
||||
$query =~ s/\/\*.*?\*\///sg;
|
||||
|
||||
#
|
||||
# Strip SQL line-oriented comments
|
||||
#
|
||||
foreach my $line (split(/\n/,$query)) {
|
||||
next if $line =~ /^\s*$/;
|
||||
$line =~ s/--.*$//;
|
||||
$result .= "$line\n";
|
||||
}
|
||||
|
||||
return $result;
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: _debug
|
||||
# PURPOSE: Prints debug reports
|
||||
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
||||
# $message Message to print
|
||||
# @messages Messages to print
|
||||
# RETURNS: Nothing
|
||||
# DESCRIPTION: Outputs a message if $active is true. It removes any trailing
|
||||
# newline and then adds one in the 'print' to the caller doesn't
|
||||
# have to bother. Prepends the message with 'D> ' to show it's
|
||||
# DESCRIPTION: Outputs messages if $active is true. It removes any trailing
|
||||
# newlines and then adds one to each line so the caller doesn't
|
||||
# have to bother. Prepends 'D> ' to each message to show it's
|
||||
# a debug message.
|
||||
# THROWS: No exceptions
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub _debug {
|
||||
my ( $active, $message ) = @_;
|
||||
sub _debug { #{{{
|
||||
my ( $active, @messages ) = @_;
|
||||
|
||||
chomp($message);
|
||||
print STDERR "D> $message\n" if $active;
|
||||
}
|
||||
if ($active) {
|
||||
chomp(@messages);
|
||||
say STDERR "D> ", join( "\nD> ", @messages );
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: _dbargs
|
||||
@@ -336,17 +384,17 @@ sub _debug {
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub _dbargs {
|
||||
sub _dbargs { #{{{
|
||||
my ($opts) = @_;
|
||||
|
||||
my @args;
|
||||
|
||||
if ( defined( $opts->{dbargs} ) ) {
|
||||
@args = @{ $opts->{dbargs} };
|
||||
if ( defined( $opts->{dbarg} ) ) {
|
||||
@args = @{ $opts->{dbarg} };
|
||||
}
|
||||
|
||||
return (@args);
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: Options
|
||||
@@ -358,7 +406,7 @@ sub _dbargs {
|
||||
# COMMENTS: none
|
||||
# SEE ALSO: n/a
|
||||
#===============================================================================
|
||||
sub Options {
|
||||
sub Options { #{{{
|
||||
my ($optref) = @_;
|
||||
|
||||
my @options = (
|
||||
@@ -371,7 +419,7 @@ sub Options {
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} #}}}
|
||||
|
||||
__END__
|
||||
|
||||
@@ -386,12 +434,12 @@ query2json - A script for generating CSV from database query
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
This documentation refers to query2json version 0.0.3
|
||||
This documentation refers to query2json version 0.0.4
|
||||
|
||||
=head1 USAGE
|
||||
|
||||
query2json [-help] [-documentation|-man] [-debug=N] [-config=FILE]
|
||||
[-query=FILE] [-output=FILE] [-[no]header] [QUERY]
|
||||
[-query=FILE] [-output=FILE] [QUERY]
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
@@ -461,11 +509,6 @@ 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
|
||||
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
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
@@ -26,9 +26,9 @@
|
||||
# BUGS: ---
|
||||
# NOTES: ---
|
||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||
# VERSION: 0.0.8
|
||||
# VERSION: 0.0.9
|
||||
# CREATED: 2021-06-18 13:24:49
|
||||
# REVISION: 2025-05-06 16:39:25
|
||||
# REVISION: 2025-05-25 18:41:09
|
||||
#
|
||||
#===============================================================================
|
||||
|
||||
@@ -54,7 +54,7 @@ use Data::Dumper;
|
||||
#
|
||||
# Version number (manually incremented)
|
||||
#
|
||||
our $VERSION = '0.0.8';
|
||||
our $VERSION = '0.0.9';
|
||||
|
||||
#
|
||||
# Script and directory names
|
||||
@@ -119,7 +119,6 @@ pod2usage(
|
||||
-noperldoc => 0,
|
||||
) if ( $options{'documentation'} );
|
||||
|
||||
|
||||
#
|
||||
# Collect options
|
||||
#
|
||||
@@ -164,11 +163,21 @@ else {
|
||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||
|
||||
#
|
||||
# Count placeholders in the query and the arguments provided
|
||||
# Strip SQL comments
|
||||
#
|
||||
$query = strip_sql_comments($query);
|
||||
|
||||
#
|
||||
# Count placeholders in the query and the arguments provided. First remove all
|
||||
# comments which may contain '?' characters, then count any that are left.
|
||||
#
|
||||
#$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
||||
$pcount = grep {/\?/} split( '', $query );
|
||||
$acount = scalar(@dbargs);
|
||||
|
||||
#
|
||||
# Check the placeholder and argument counts are the same
|
||||
#
|
||||
if ( $pcount ne $acount) {
|
||||
say STDERR "Query placeholder vs argument mismatch";
|
||||
say STDERR "Placeholders = $pcount, Arguments = $acount";
|
||||
@@ -319,13 +328,13 @@ exit;
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub db_connect {
|
||||
sub db_connect { #{{{
|
||||
my ($cfg) = @_;
|
||||
|
||||
my ( $dbh, $dbtype, $dbname );
|
||||
|
||||
$dbtype = $config{database}->{dbtype};
|
||||
$dbname = $config{database}->{name};
|
||||
$dbtype = $cfg->{database}->{dbtype};
|
||||
$dbname = $cfg->{database}->{name};
|
||||
die "Database name is mandatory\n" unless $dbname;
|
||||
|
||||
#
|
||||
@@ -336,6 +345,7 @@ sub db_connect {
|
||||
# The name for the SQLite driver is 'DBD:SQLite'
|
||||
#
|
||||
$dbtype = 'SQLite';
|
||||
_debug( $DEBUG >= 3, '$dbtype: ' . $dbtype, '$dbname: ' . $dbname );
|
||||
|
||||
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
||||
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
||||
@@ -347,10 +357,10 @@ sub db_connect {
|
||||
#
|
||||
$dbtype = 'mysql';
|
||||
|
||||
my $dbhost = $config{database}->{host};
|
||||
my $dbport = $config{database}->{port};
|
||||
my $dbuser = $config{database}->{user};
|
||||
my $dbpwd = $config{database}->{password};
|
||||
my $dbhost = $cfg->{database}->{host};
|
||||
my $dbport = $cfg->{database}->{port};
|
||||
my $dbuser = $cfg->{database}->{user};
|
||||
my $dbpwd = $cfg->{database}->{password};
|
||||
|
||||
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
||||
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
||||
@@ -376,28 +386,68 @@ sub db_connect {
|
||||
}
|
||||
|
||||
return $dbh;
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: strip_sql_comments
|
||||
# PURPOSE: Given a query as a scalar, strips all SQL comments
|
||||
# PARAMETERS: $query string containing a query
|
||||
# RETURNS: Stripped string
|
||||
# DESCRIPTION: Two types of comments might exist in the query: the C-style
|
||||
# and the SQL style. The string is treated as a single string
|
||||
# even though it's multi-line, and any C-style comments are
|
||||
# removed. Then the string is treated as multi-line and each
|
||||
# line is scanned for SQL comments (which end at the end of the
|
||||
# line), and these are stripped. Blank lines are skipped too to
|
||||
# compress the output a little.
|
||||
# THROWS: No exceptions
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub strip_sql_comments { #{{{
|
||||
my ($query) = @_;
|
||||
|
||||
my $result;
|
||||
|
||||
#
|
||||
# Strip C-style comments
|
||||
#
|
||||
$query =~ s/\/\*.*?\*\///sg;
|
||||
|
||||
#
|
||||
# Strip SQL line-oriented comments
|
||||
#
|
||||
foreach my $line (split(/\n/,$query)) {
|
||||
next if $line =~ /^\s*$/;
|
||||
$line =~ s/--.*$//;
|
||||
$result .= "$line\n";
|
||||
}
|
||||
|
||||
return $result;
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: _debug
|
||||
# PURPOSE: Prints debug reports
|
||||
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
||||
# $message Message to print
|
||||
# @messages Messages to print
|
||||
# RETURNS: Nothing
|
||||
# DESCRIPTION: Outputs a message if $active is true. It removes any trailing
|
||||
# newline and then adds one in the 'print' to the caller doesn't
|
||||
# have to bother. Prepends the message with 'D> ' to show it's
|
||||
# DESCRIPTION: Outputs messages if $active is true. It removes any trailing
|
||||
# newlines and then adds one to each line so the caller doesn't
|
||||
# have to bother. Prepends 'D> ' to each message to show it's
|
||||
# a debug message.
|
||||
# THROWS: No exceptions
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub _debug {
|
||||
my ( $active, $message ) = @_;
|
||||
sub _debug { #{{{
|
||||
my ( $active, @messages ) = @_;
|
||||
|
||||
chomp($message);
|
||||
print STDERR "D> $message\n" if $active;
|
||||
}
|
||||
if ($active) {
|
||||
chomp(@messages);
|
||||
say STDERR "D> ", join( "\nD> ", @messages );
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: _dbargs
|
||||
@@ -410,17 +460,17 @@ sub _debug {
|
||||
# COMMENTS: None
|
||||
# SEE ALSO: N/A
|
||||
#===============================================================================
|
||||
sub _dbargs {
|
||||
sub _dbargs { #{{{
|
||||
my ($opts) = @_;
|
||||
|
||||
my @args;
|
||||
|
||||
if ( defined( $opts->{dbargs} ) ) {
|
||||
@args = @{ $opts->{dbargs} };
|
||||
if ( defined( $opts->{dbarg} ) ) {
|
||||
@args = @{ $opts->{dbarg} };
|
||||
}
|
||||
|
||||
return (@args);
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: _define
|
||||
@@ -435,7 +485,7 @@ sub _dbargs {
|
||||
# COMMENTS: None
|
||||
# SEE ALSO:
|
||||
#===============================================================================
|
||||
sub _define {
|
||||
sub _define { #{{{
|
||||
my ($opts) = @_;
|
||||
|
||||
my %defs;
|
||||
@@ -445,7 +495,7 @@ sub _define {
|
||||
}
|
||||
|
||||
return (%defs);
|
||||
}
|
||||
} #}}}
|
||||
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: Options
|
||||
@@ -457,14 +507,14 @@ sub _define {
|
||||
# COMMENTS: none
|
||||
# SEE ALSO: n/a
|
||||
#===============================================================================
|
||||
sub Options {
|
||||
sub Options { #{{{
|
||||
my ($optref) = @_;
|
||||
|
||||
my @options = (
|
||||
"help", "documentation|man",
|
||||
"debug=i", "config=s",
|
||||
"output=s", "query=s",
|
||||
"template=s", "dbargs=s@",
|
||||
"template=s", "dbarg=s@",
|
||||
"define=s%",
|
||||
);
|
||||
|
||||
@@ -473,7 +523,7 @@ sub Options {
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} #}}}
|
||||
|
||||
__END__
|
||||
|
||||
@@ -488,7 +538,7 @@ query2tt2 - A script for formatting a report from database query using a templat
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
This documentation refers to query2tt2 version 0.0.8
|
||||
This documentation refers to query2tt2 version 0.0.9
|
||||
|
||||
=head1 USAGE
|
||||
|
||||
|
135
hpr_container_email_shownotes.sh
Executable file
135
hpr_container_email_shownotes.sh
Executable file
@@ -0,0 +1,135 @@
|
||||
#!/usr/bin/env bash
|
||||
#License: GPL v3
|
||||
#see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#Name: button_hpr_container.sh
|
||||
#Purpose: build/run HPR Container.
|
||||
#Version: beta 0.01
|
||||
#Author: SGOTI (Some Guy On The Internet)
|
||||
#Email: Lyunpaw@gmail.com
|
||||
#Date: 2025-04-19
|
||||
|
||||
#declaration:
|
||||
declare bindir="/usr/bin/"
|
||||
declare podman="${bindir}podman"
|
||||
declare echo="builtin echo -e"
|
||||
declare unprivilegedUser="janitor"
|
||||
declare date="${bindir}date"
|
||||
declare flags
|
||||
declare OPTIND
|
||||
declare -A containerBulidProperties
|
||||
|
||||
declare currentMonth
|
||||
declare nextMonth
|
||||
declare currentYear
|
||||
|
||||
#start:
|
||||
currentMonth=$(${date} +%m)
|
||||
currentYear=$(${date} +%Y)
|
||||
|
||||
if [[ ${currentmonth} -gt 0 ]] && [[ ${currentmonth} -le 11 ]]; then
|
||||
nextMonth="(($(${date} +%m)+01))" #Incomplete: Can return single-digit integer; must be a double-digit integer.
|
||||
else
|
||||
nextMonth="01"
|
||||
fi
|
||||
|
||||
containerBulidProperties=(
|
||||
"containerFile" "/path/to/Containerfile"
|
||||
"hostMountDir01" "/path/to/project/directory"
|
||||
"hostMountDir02" "/tmp/"
|
||||
"containerMountDir01" "/opt/hpr/"
|
||||
"containerMountDir02" "/tmp/hpr/"
|
||||
"containerImageTag" "hpr_image:5.40.1"
|
||||
"pullNewImage" "podman pull docker.io/library/perl"
|
||||
"recordingDate" "$(${date} -d "${currentYear}/${currentMonth}/01")"
|
||||
"recordingTimeStart" "15:00" #TZ: UTC
|
||||
"recordingTimeEnd" "17:00" #TZ: UTC
|
||||
)
|
||||
|
||||
function runHPRContainer () {
|
||||
local makeEmail #Incomplete:
|
||||
makeEmail="./make_email -month=${containerBulidProperties[recordingDate]} -start=15:00 -end=17:00 -out=/tmp/hpr/%semail.txt"
|
||||
local makeShownotes #Incomplete:
|
||||
makeShownotes="/opt/hpr/src/hpr-tools/Community_News/make_shownotes -from=${containerBulidProperties[recordingDate]} -full=/tmp/hpr/%sfull_shownotes.html -mail -comments"
|
||||
|
||||
${podman} run \
|
||||
--mount type=bind,src=${containerBulidProperties[hostMountDir02]},dst=${containerBulidProperties[containerMountDir02]},rw=true \
|
||||
--label="Project"="HPR" \
|
||||
--label="Forge"="https://repo.anhonesthost.net/HPR/" \
|
||||
--interactive \
|
||||
--tty \
|
||||
--rm=true \
|
||||
--privileged=false \
|
||||
--pull="never" \
|
||||
--cgroups=enabled \
|
||||
--cgroupns=private \
|
||||
--uts=private \
|
||||
--pid=private \
|
||||
--memory="32m" \
|
||||
--memory-reservation="16m" \
|
||||
--hostname="hpr" \
|
||||
--name="hpr_project" \
|
||||
--user="${unprivilegedUser}" \
|
||||
${containerBulidProperties[containerImageTag]} bash;
|
||||
return;
|
||||
}
|
||||
|
||||
function buildNewContainerImage () {
|
||||
if [[ -f "${containerBulidProperties[containerFile]}" ]]; then
|
||||
${echo} "Building new container image...\nThis may take several minutes.\
|
||||
\nThis is a non interactive build process, so you can return when \
|
||||
it's completed.";
|
||||
${podman} build --file="${containerBulidProperties[containerFile]}" --tag="${containerBulidProperties[containerImageTag]}";
|
||||
else
|
||||
${echo} 'Dont forget to assign the ${containerBulidProperties[containerFile]} ;). The Containerfile is needed to build the container image.'
|
||||
fi
|
||||
return;
|
||||
}
|
||||
|
||||
function help () {
|
||||
${echo} "$0 [-hbpq]\n\t[-h] help\n\t[-b] build new container\n\t[-p] pull new perl image\n\t[-q] quit";
|
||||
return;
|
||||
}
|
||||
|
||||
while getopts 'hbpq' flags; do
|
||||
case "${flags}" in
|
||||
h) help; exit 0;
|
||||
;;
|
||||
|
||||
i) ${echo} "Work in progress... :D"; break;
|
||||
;;
|
||||
|
||||
b) buildNewContainerImage;
|
||||
;;
|
||||
|
||||
p) ${containerBulidProperties[pullNewImage]}; exit 0;
|
||||
;;
|
||||
|
||||
e) ${echo} "Work in progress... :D"; break;
|
||||
;;
|
||||
|
||||
s) ${echo} "Work in progress... :D"; break;
|
||||
;;
|
||||
|
||||
q)
|
||||
${echo} "Quitting script."; break;
|
||||
;;
|
||||
|
||||
*)
|
||||
${echo} "Good Heavens! Wrong input."; help; exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [[ -z ${1} ]]; then help; runHPRContainer; fi;
|
||||
|
||||
unset echo
|
||||
unset flags
|
||||
unset podman
|
||||
unset OPTIND
|
||||
unset currentMonth
|
||||
unset currentYear
|
||||
unset containerBulidProperties
|
||||
exit 0
|
||||
|
@@ -2,7 +2,14 @@
|
||||
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
|
||||
#============================================================
|
||||
|
||||
find ${HOME}/processing/ -type f | egrep -v '/sponsor-anhonesthost.com-hpr15.flac|/outro.flac|/intro.flac|/sponsor-archive.org.flac' | while read mediafile
|
||||
search_dir="${HOME}/processing/"
|
||||
|
||||
if [ -d "${1}" ]
|
||||
then
|
||||
search_dir="${1}"
|
||||
fi
|
||||
|
||||
find ${search_dir} -type f | grep -vP '/sponsor-anhonesthost.com-hpr15.flac|/outro.flac|/intro.flac|/sponsor-archive.org.flac' | while read mediafile
|
||||
do
|
||||
duration=$( mediainfo --full --Output=XML "${mediafile}" | xmlstarlet sel -T -t -m "_:MediaInfo/_:media/_:track[@type='Audio']/_:Duration[1]" -v "." -n - | awk -F '.' '{print $1}' )
|
||||
if [ "${duration}" != "" ]
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user