-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-image-sponsors.pl
executable file
·58 lines (51 loc) · 1.52 KB
/
get-image-sponsors.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
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::UserAgent;
use HTML::PullParser;
use Data::Dumper;
my $ua = LWP::UserAgent->new;
my $host = 'https://www.perl.dance';
my $res = $ua->get("$host/sponsors");
if ($res->is_success) {
my $content = $res->decoded_content;
if ($content =~ m/(<div id="sponsors".*)<div class="footer">/) {
my $stanza = $1;
open (my $fh, '>:encoding(UTF-8)', 'sponsors.tex') or die;
print $fh parse_sponsors($stanza);
close $fh;
}
}
sub parse_sponsors {
my $body = shift;
my $tex = "\\begin{center}\n";
my $parser = HTML::PullParser->new(doc => \$body,
start => '"S", tagname, attr',
text => '"T", dtext');
my $current = '';
while (my $token = $parser->get_token) {
# print Dumper($token);
my ($type, $text, $attrs) = @$token;
if ($type eq 'T') {
$current .= $text;
}
elsif ($type eq 'S') {
if ($text eq 'img' and $attrs->{src}) {
if ($current) {
$tex .= <<"EOF";
\\vfill
\\textbf{\\Large \\textsf{$current}}
\\vfill
EOF
$current = '';
}
my $target = $attrs->{src};
$target =~ s/^\///;
$tex .= "\\includegraphics[height=1.5cm]{$target}\n";
$ua->mirror($host . $attrs->{src}, $target);
}
}
}
$tex .= "\\vfill\n\\end{center}";
return $tex;
}