X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=parse%2Fparse-wiki-songlist.pl;h=4303c2d39bdf31a504e2e7f33f1935d4a7ee0d8c;hp=49934c84d4327a005fed9fce9a86d228d1108c19;hb=12f6f1727b74581d318163d769318a5794076935;hpb=a24b59a81c140c475c5ecfd195e562cf67e5b607 diff --git a/parse/parse-wiki-songlist.pl b/parse/parse-wiki-songlist.pl index 49934c8..4303c2d 100644 --- a/parse/parse-wiki-songlist.pl +++ b/parse/parse-wiki-songlist.pl @@ -2,13 +2,18 @@ use strict; use warnings; +my $machine = shift; +die "Missing machine (first argument on the command line)" if (!defined($machine)); + # Parses songlist from the DDRNO wiki +print "begin;\n"; + while (<>) { m/ \| \s* \[\[ (.*?) \]\] \s* # song name \|\| \s* \[\[ (.*?) \]\] \s* # artist - \|\| \s* (\d+(-\d+)?) \s* # bpm + \|\| \s* (\d+(?:-(\d+))?) \s* # bpm \|\| \s* (\d+) \s* # single beginner \|\| \s* (\d+) \s* # single standard \|\| \s* (\d+) \s* # single difficult @@ -27,8 +32,8 @@ while (<>) { $artist =~ s/\[\[//g; # minimal SQL escaping - $songname =~ s/'/\'/g; - $artist =~ s/'/\'/g; + $songname =~ s/'/\\'/g; + $artist =~ s/'/\\'/g; $maxbpm = $minbpm if (!defined($maxbpm)); ($maxbpm,$minbpm) = ($minbpm,$maxbpm) if ($maxbpm < $minbpm); @@ -43,8 +48,9 @@ while (<>) { ['double', 'standard', $ds], ['double', 'difficult', $dd], ['double', 'expert', $de]) { - printf "INSERT INTO songratings (song,playmode,difficulty,feetrating) VALUES ((SELECT song FROM songs WHERE title='%s'),'%s','%s',%u);\n", - $songname, $t->[0], $t->[1], $t->[2]; + printf "INSERT INTO songratings (song,machine,playmode,difficulty,feetrating) VALUES ((SELECT song FROM songs WHERE title='%s'),(SELECT machine FROM machines WHERE machinename='%s'),'%s','%s',%u);\n", + $songname, $machine, $t->[0], $t->[1], $t->[2]; } - } + +printf "commit;\n";