-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminer
executable file
·53 lines (53 loc) · 1.56 KB
/
miner
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
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl -w
# The main datamine: hash of name => { time , src }
our %mine;
# First read the existing datamine file if present
if (open MINE, "mine.csv") {
while (<MINE>) {
my ($name, $time, $src) = split '[,;\n]';
$time =~ s/_(\d)(_|\b)/_0$1$2/g;
$mine{$name} = { time => $time, src => $src };
}
close MINE;
}
# Go through html files to extend the datamine
opendir NAPI, "." or die $!;
foreach (readdir NAPI) {
if (/\.jpe?g/i) {
my @mtime = localtime ((stat $_)[9]);
$mtime[5] += 1900;
$mtime[4]++;
$mtime[4] =~ s/^(\d)$/0$1/;
$mtime[3] =~ s/^(\d)$/0$1/;
my $time = "$mtime[5]_$mtime[4]_$mtime[3]";
$mine{$_}{time} = $time unless $mine{$_}{time};
} elsif (/^(.+)\.html/) {
my $basename = $1;
my ($month, $src);
if ($basename =~ /^\d{4}_\d{2}$/) {
$src = 'napi';
$month = $basename;
} else {
($src = $basename) =~ s/^index$/napi/;
}
my $i = 0;
open HTML, $_ or die $!;
while (<HTML>) {
$i++;
next unless (/rajz=(.+)">/);
my $name = $1;
(my $day = 39 - $i) =~ s/^(\d)$/0$1/;
my $time = $month . "_$day" if $month;
$mine{$name}{time} = $time if $time;
$mine{$name}{src} = $src;
}
close HTML;
}
}
closedir NAPI;
# Print csv
open MINE, ">mine.csv" or die $!;
foreach (sort { $mine{$a}{time} cmp $mine{$b}{time} } keys %mine) {
print MINE "$_;$mine{$_}{time};$mine{$_}{src}\n";
}
close MINE;