]> git.sesse.net Git - ccbs/blob - html/songratings-text.pl
Port to pqxx3, where we need the widestring traits available at parse time.
[ccbs] / html / songratings-text.pl
1 #! /usr/bin/perl
2
3 use ccbs;
4 use strict;
5 use warnings;
6
7 my $cgi = new CGI;
8 my $machine = $cgi->param('machine');
9
10 my $dbh = ccbs::db_connect();
11
12 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);
13
14 my @songs = ();
15
16 my $last_song = -1;
17 for my $song (@$songs_raw) {
18         if ($song->{'song'} != $last_song) {
19                 push @songs, { song => $song->{'song'}, title => $song->{'title'}, artist => $song->{'artist'} };
20         }
21
22         my $key = $song->{'playmode'} . '_' . $song->{'difficulty'};
23         $songs[$#songs]->{$key} = $song->{'feetrating'};
24         $last_song = $song->{'song'};
25 }
26
27 print CGI::header(-type=>'text/plain; charset=utf-8');
28 my $config = {
29         INCLUDE_PATH => 'templates/',
30         INTERPOLATE  => 1,
31         POST_CHOMP   => 1,
32         EVAL_PERL    => 1,
33 };
34 my $template = Template->new($config);
35
36 my $output = '';
37 $template->process('songratings-text.tmpl', { songs => \@songs }, \$output)
38 or die $template->error();
39
40 print $output;
41
42 $dbh->disconnect;