From 4dce0fb0cd97f705af2e169fe6fdf7eb6e458304 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 24 Apr 2005 21:57:02 +0000 Subject: [PATCH] Pull from --pgweb. Patches applied: * sgunderson@bigfoot.com--2005-private/ccbs--pgweb--1.0--patch-37 Add a script for exporting the song list of a machine to a simple SQL-ish text format. --- html/songratings-text.pl | 42 ++++++++++++++++++++++++++++ html/templates/songratings-text.tmpl | 32 +++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 html/songratings-text.pl create mode 100644 html/templates/songratings-text.tmpl diff --git a/html/songratings-text.pl b/html/songratings-text.pl new file mode 100755 index 0000000..44b1d0f --- /dev/null +++ b/html/songratings-text.pl @@ -0,0 +1,42 @@ +#! /usr/bin/perl + +use ccbs; +use strict; +use warnings; + +my $cgi = new CGI; +my $machine = $cgi->param('machine'); + +my $dbh = ccbs::db_connect(); + +my $songs_raw = ccbs::db_fetch_all($dbh, 'SELECT song,title,artist,playmode,difficulty,feetrating FROM songratings NATURAL JOIN songs WHERE machine=? ORDER BY LOWER(title)', $machine); + +my @songs = (); + +my $last_song = -1; +for my $song (@$songs_raw) { + if ($song->{'song'} != $last_song) { + push @songs, { song => $song->{'song'}, title => $song->{'title'}, artist => $song->{'artist'} }; + } + + my $key = $song->{'playmode'} . '_' . $song->{'difficulty'}; + $songs[$#songs]->{$key} = $song->{'feetrating'}; + $last_song = $song->{'song'}; +} + +print CGI::header(-type=>'text/plain; charset=utf-8'); +my $config = { + INCLUDE_PATH => 'templates/', + INTERPOLATE => 1, + POST_CHOMP => 1, + EVAL_PERL => 1, +}; +my $template = Template->new($config); + +my $output = ''; +$template->process('songratings-text.tmpl', { songs => \@songs }, \$output) +or die $template->error(); + +print $output; + +$dbh->disconnect; diff --git a/html/templates/songratings-text.tmpl b/html/templates/songratings-text.tmpl new file mode 100644 index 0000000..5087350 --- /dev/null +++ b/html/templates/songratings-text.tmpl @@ -0,0 +1,32 @@ +[%# vim:set filetype=html: %] +[% FOR s = songs %] +[% IF s.single_beginner == '' %] +[% SET s.single_beginner = 'NULL' %] +[% END %] +[% IF s.single_standard == '' %] +[% SET s.single_standard = 'NULL' %] +[% END %] +[% IF s.single_difficult == '' %] +[% SET s.single_difficult = 'NULL' %] +[% END %] +[% IF s.single_expert == '' %] +[% SET s.single_expert = 'NULL' %] +[% END %] +[% IF s.single_challenge == '' %] +[% SET s.single_challenge = 'NULL' %] +[% END %] +[% IF s.double_standard == '' %] +[% SET s.double_standard = 'NULL' %] +[% END %] +[% IF s.double_difficult == '' %] +[% SET s.double_difficult = 'NULL' %] +[% END %] +[% IF s.double_expert == '' %] +[% SET s.double_expert = 'NULL' %] +[% END %] +[% IF s.double_challenge == '' %] +[% SET s.double_challenge = 'NULL' %] +[% END %] +'[% s.title %]', '[% s.artist %]', [% s.single_beginner%], [% s.single_standard%], [% s.single_difficult%], [% s.single_expert%], [% s.single_challenge%], [% s.double_standard%], [% s.double_difficult%], [% s.double_expert%], [% s.double_challenge %] + +[% END %] -- 2.39.2