-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetdata.pl
47 lines (36 loc) · 1004 Bytes
/
getdata.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
43
44
45
46
47
#!/usr/bin/perl
use strict;
use warnings;
use Mojo::UserAgent;
use JSON::XS;
use File::Slurp::Unicode;
my $datafile = shift || "data.json";
my $data = {};
if (-f $datafile) {
$data = decode_json(read_file($datafile));
}
my $ua = Mojo::UserAgent->new;
my %exists;
while (<>) {
next if m/^\s*#/;
next unless m/(\d+)/;
my $num = $1;
$exists{$num} = 1;
next if $data->{$num};
my $url = "http://tools.ietf.org/html/rfc$num";
my @meta = $ua->get($url)->res->dom->html->head->meta->each();
foreach my $item (@meta) {
next unless $item->{name};
next unless $item->{name} eq 'DC.Title';
$data->{$num} = $item->{content};
write_file($datafile, JSON::XS->new->pretty(1)->encode($data));
}
}
foreach my $key (keys %$data) {
next if $exists{$key};
delete $data->{$key};
write_file($datafile, JSON::XS->new->pretty(1)->encode($data));
}
foreach my $key (sort { $a <=> $b } keys %$data) {
print "$key: $data->{$key}\n";
}