-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable2csv.pl
executable file
·42 lines (37 loc) · 1009 Bytes
/
table2csv.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env perl
# table2csv.pl by Amory Meltzer
# Licensed under the WTFPL http://www.wtfpl.net/
# Process the table from XTools, convert the relevant to csv
use 5.006;
use strict;
use warnings;
use diagnostics;
use English qw( -no_match_vars);
# Keep track of where we are in the document
my $thereyet = 0;
my $line;
open my $input, '<', "$ARGV[0]" or croak $ERRNO;
# We really don't need to process the column headers, I know what I want
print "User,Totals\n";
while (<$input>) {
chomp;
# Only start looking once we get to the results table
if ($thereyet == 0) {
if (/sort-entry--rank/) {
$thereyet++;
$line = $NR;
} else {
next;
}
}
# Skip the early ugliness, could probably jump ahead further...
if (/sort-entry--username/) {
s/.*sort-entry--username" data-value="(.*)">$/$1/;
s/,/-/g;
print "$_,";
} elsif (/sort-entry--total/) {
s/.*sort-entry--total" data-value="(.*)">\d+.*$/$1/;
print "$_\n";
}
}
close $input or die $ERRNO;