line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PerlMonksFlairApp; |
2
|
2
|
|
|
2
|
|
30618
|
use Dancer ':syntax'; |
|
2
|
|
|
|
|
1314495
|
|
|
2
|
|
|
|
|
13
|
|
3
|
2
|
|
|
2
|
|
4339
|
use WWW::Mechanize; |
|
2
|
|
|
|
|
1105764
|
|
|
2
|
|
|
|
|
89
|
|
4
|
2
|
|
|
2
|
|
41
|
use HTML::TokeParser; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
275892
|
use GD; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
set logger => 'file'; |
8
|
|
|
|
|
|
|
set log => info; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
get '/' => sub { |
13
|
|
|
|
|
|
|
return template 'index'; |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
get qr{/([\w -.]+)\.jpg} => sub { |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my ($req_username) = splat; |
18
|
|
|
|
|
|
|
info("User => $req_username"); |
19
|
|
|
|
|
|
|
my $xp = 0;#experience |
20
|
|
|
|
|
|
|
my $wr = 0;#writeups |
21
|
|
|
|
|
|
|
my $lvl = "";#level |
22
|
|
|
|
|
|
|
my $agent = WWW::Mechanize->new(); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$agent->get("http://www.perlmonks.org/?node=$req_username&type=user"); |
25
|
|
|
|
|
|
|
# debug $agent->{content}; # bah dummy. You're always looking at a logged out version of the page from code! |
26
|
|
|
|
|
|
|
my $stream = HTML::TokeParser->new(\$agent->{content}); |
27
|
|
|
|
|
|
|
my $username = "-none-"; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if ($stream->get_tag('title')) { |
30
|
|
|
|
|
|
|
$username = $stream->get_trimmed_text; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
#if the title is Super Search then username supplied is incorrect. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
while(my $tag = $stream->get_tag('td')) |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
# $tag will contain this array => [$tag, $attr, $attrseq, $text] |
37
|
|
|
|
|
|
|
if($stream->get_trimmed_text("/td") eq "Experience:") { |
38
|
|
|
|
|
|
|
$stream->get_tag('td'); |
39
|
|
|
|
|
|
|
$xp = $stream->get_trimmed_text("/td"); |
40
|
|
|
|
|
|
|
#debug "Set xp"; |
41
|
|
|
|
|
|
|
$stream->get_tag("td"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
if($stream->get_trimmed_text("/td") eq "Level:") { |
44
|
|
|
|
|
|
|
$stream->get_tag('td'); |
45
|
|
|
|
|
|
|
$lvl = $stream->get_trimmed_text("/td"); |
46
|
|
|
|
|
|
|
#debug "set lvl"; |
47
|
|
|
|
|
|
|
$stream->get_tag("td"); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
if($stream->get_trimmed_text("/td") eq "Writeups:") { |
50
|
|
|
|
|
|
|
$stream->get_tag('td'); |
51
|
|
|
|
|
|
|
$wr = $stream->get_trimmed_text("/td"); |
52
|
|
|
|
|
|
|
#debug "set witeups"; |
53
|
|
|
|
|
|
|
$stream->get_tag("td"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
$lvl =~ m/(\d+)/; |
57
|
|
|
|
|
|
|
my $l = $1;#just moved to another variable for feeling's sake. |
58
|
|
|
|
|
|
|
#debug "$username => Xp: $xp\n $wr level = $lvl L =$l"; |
59
|
|
|
|
|
|
|
# my $to_print = "$username\nLevel: $lvl\nExperience: $xp"; |
60
|
|
|
|
|
|
|
my $im = undef; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
eval { |
63
|
|
|
|
|
|
|
$im = newFromJpeg GD::Image(join('/', setting('public'), "/badges/$l.jpg")) ; |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
$im->trueColor(1); |
66
|
|
|
|
|
|
|
my $white = $im->colorResolve(255,255,255); |
67
|
|
|
|
|
|
|
my $black = $im->colorResolve(0,0,0); |
68
|
|
|
|
|
|
|
#debug "color is: $black"; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $xp_color = $white; |
71
|
|
|
|
|
|
|
if($xp =~ /none/) |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
$xp = 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
if($xp >= 250 and $xp < 400) |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
$xp_color = $black; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
$im->stringFT($black, join('/', setting('public'), '/Open_Sans/OpenSans-Bold.ttf'),10 , 0, 110, 40, $username); |
80
|
|
|
|
|
|
|
$im->stringFT($black, join('/', setting('public'), '/Open_Sans/OpenSans-Bold.ttf'), 9, 0, 110, 60, $lvl); |
81
|
|
|
|
|
|
|
$im->stringFT($xp_color, join('/', setting('public'), '/Open_Sans/OpenSans-Bold.ttf'), 9 , 0, 110, 75, "Experience ".$xp); |
82
|
|
|
|
|
|
|
#debug "Error opening image: $@" if $@; |
83
|
|
|
|
|
|
|
content_type 'image/jpeg'; |
84
|
|
|
|
|
|
|
return $im->jpeg; |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
true; |
88
|
|
|
|
|
|
|
__END__ #END of module |