line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Hatena::WanWanWorld::position; |
2
|
1
|
|
|
1
|
|
24059
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
147
|
|
4
|
|
|
|
|
|
|
|
5
|
0
|
|
|
0
|
|
|
sub lat { &WWW::Hatena::Scraper::_getset; } |
6
|
0
|
|
|
0
|
|
|
sub long { &WWW::Hatena::Scraper::_getset; } |
7
|
|
|
|
|
|
|
sub position { |
8
|
0
|
|
|
0
|
|
|
my $self = shift; |
9
|
0
|
0
|
|
|
|
|
if (@_ == 2) { |
|
|
0
|
|
|
|
|
|
10
|
0
|
|
|
|
|
|
$self->lat(shift); |
11
|
0
|
|
|
|
|
|
$self->long(shift); |
12
|
|
|
|
|
|
|
} elsif (@_ != 0) { |
13
|
0
|
|
|
|
|
|
croak ("Number of parameters are invalid"); |
14
|
|
|
|
|
|
|
} |
15
|
0
|
|
|
|
|
|
return ($self->lat,$self->long); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package WWW::Hatena::WanWanWorld; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
21
|
|
21
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
22
|
1
|
|
|
1
|
|
10
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
60
|
|
23
|
|
|
|
|
|
|
$VERSION = '0.02'; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
4
|
use base qw(WWW::Hatena::Scraper WWW::Hatena::WanWanWorld::position); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
785
|
|
26
|
|
|
|
|
|
|
use Digest::MD5 qw(md5_base64); |
27
|
|
|
|
|
|
|
use JSON; |
28
|
|
|
|
|
|
|
use Location::GeoTool; |
29
|
|
|
|
|
|
|
use Encode; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Encode::Alias::define_alias( qr/^euc$/i => '"euc-jp"' ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my %opts = @_; |
36
|
|
|
|
|
|
|
$opts{labo} = 1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$opts{user_check_code} = sub { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my $content = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my ($user) = $content =~ /var\smyName\s*=\s*'([^']+)';/; |
43
|
|
|
|
|
|
|
$self->user($user); |
44
|
|
|
|
|
|
|
my ($long,$lat) = $content =~ /var\sstart\s*=\s*\[([\d\.]+),\s*([\d\.]+)\];/; |
45
|
|
|
|
|
|
|
$self->lat($lat); |
46
|
|
|
|
|
|
|
$self->long($long); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->user; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
$opts{user_check_url} = "http://world.hatelabo.jp/"; |
51
|
|
|
|
|
|
|
my $charcode = delete $opts{'charcode'} || 'encode'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self = $self->WWW::Hatena::Scraper::new(%opts); |
54
|
|
|
|
|
|
|
$self->logout_url("http://world.hatelabo.jp/logout"); |
55
|
|
|
|
|
|
|
$self->charcode($charcode); |
56
|
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub friends { &WWW::Hatena::Scraper::_getset; } |
60
|
|
|
|
|
|
|
sub arounds { &WWW::Hatena::Scraper::_getset; } |
61
|
|
|
|
|
|
|
sub markers { &WWW::Hatena::Scraper::_getset; } |
62
|
|
|
|
|
|
|
sub voice { &WWW::Hatena::Scraper::_getset; } |
63
|
|
|
|
|
|
|
sub charcode { &WWW::Hatena::Scraper::_getset; } |
64
|
|
|
|
|
|
|
sub json { |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
$self->{'json'} ||= JSON->new(unmapping => 1, quotapos => 1 , barekey => 1,utf8 => $self->charcode eq 'encode' ? 1: 0); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_around { |
70
|
|
|
|
|
|
|
my $self = shift; |
71
|
|
|
|
|
|
|
my $km = shift; |
72
|
|
|
|
|
|
|
my $rkm = md5_base64($self->rk); |
73
|
|
|
|
|
|
|
my $voice = $self->encoded_voice() || ''; |
74
|
|
|
|
|
|
|
my ($lat,$long,$minY,$minX,$maxY,$maxX) = $self->get_minmax($km); |
75
|
|
|
|
|
|
|
my $content = "z=1&lat=${long}&lng=${lat}&voice=${voice}&rkm=${rkm}&minX=${minX}&maxX=${maxX}&minY=${minY}&maxY=${maxY}&_="; |
76
|
|
|
|
|
|
|
my $json = $self->json->jsonToObj($self->get_content('http://world.hatelabo.jp/position',$content)); |
77
|
|
|
|
|
|
|
for my $dog (map { $json->{$_} } keys %$json) { |
78
|
|
|
|
|
|
|
my $voice = $dog->{'voice'}; |
79
|
|
|
|
|
|
|
$voice = encode($self->charcode,$voice) if ($self->charcode ne 'encode'); |
80
|
|
|
|
|
|
|
$dog->{'voice'} = $voice || ''; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
$self->arounds($json); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub get_friend { |
86
|
|
|
|
|
|
|
my $self = shift; |
87
|
|
|
|
|
|
|
my $content = shift || ''; |
88
|
|
|
|
|
|
|
my $res = $self->get_content('http://world.hatelabo.jp/friend',$content); |
89
|
|
|
|
|
|
|
if ($content eq '') { |
90
|
|
|
|
|
|
|
return $self->friends($self->json->jsonToObj($res)); |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
my ($result) = $res =~ /(.+)<\/success>/m; |
93
|
|
|
|
|
|
|
return eval {$result} || 0; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub delete_friend { |
98
|
|
|
|
|
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
my $friend = shift; |
100
|
|
|
|
|
|
|
my $rkm = md5_base64($self->rk); |
101
|
|
|
|
|
|
|
$self->get_friend("mode=delete&friendname=${friend}&rkm=${rkm}&_="); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub add_friend { |
105
|
|
|
|
|
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
my $friend = shift; |
107
|
|
|
|
|
|
|
my $rkm = md5_base64($self->rk); |
108
|
|
|
|
|
|
|
$self->get_friend("mode=add&friendname=${friend}&rkm=${rkm}&_="); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get_marker { |
112
|
|
|
|
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
my $km = shift; |
114
|
|
|
|
|
|
|
my ($lat,$long,$minY,$minX,$maxY,$maxX) = $self->get_minmax($km); |
115
|
|
|
|
|
|
|
my $content = "minX=${minX}&maxX=${maxX}&minY=${minY}&maxY=${maxY}<=20&_="; |
116
|
|
|
|
|
|
|
$self->markers($self->json->jsonToObj($self->get_content('http://world.hatelabo.jp/marker',$content))); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub add_house { |
120
|
|
|
|
|
|
|
my $self = shift; |
121
|
|
|
|
|
|
|
my ($lat,$long) = $self->position; |
122
|
|
|
|
|
|
|
my $rkm = md5_base64($self->rk); |
123
|
|
|
|
|
|
|
$self->json->jsonToObj($self->get_content('http://world.hatelabo.jp/house',"lat=${long}&lng=${lat}&mode=add&rkm=${rkm}&_=")); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub get_minmax { |
127
|
|
|
|
|
|
|
my $self = shift; |
128
|
|
|
|
|
|
|
my $km = shift; |
129
|
|
|
|
|
|
|
my ($lat,$long) = $self->position; |
130
|
|
|
|
|
|
|
my $loc = Location::GeoTool->create_coord($lat,$long,'wgs84','degree'); |
131
|
|
|
|
|
|
|
my ($minY,$minX) = $loc->direction_vector(225,$km * 1414.21356)->to_point->array; |
132
|
|
|
|
|
|
|
my $maxX = $long * 2 - $minX; |
133
|
|
|
|
|
|
|
my $maxY = $lat * 2 - $minY; |
134
|
|
|
|
|
|
|
return ($lat,$long,$minY,$minX,$maxY,$maxX); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub encoded_voice { |
138
|
|
|
|
|
|
|
my $self = shift; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $voice = $self->voice; |
141
|
|
|
|
|
|
|
$voice = decode($self->charcode,$voice) if ($self->charcode ne 'encode'); |
142
|
|
|
|
|
|
|
Encode::_utf8_off($voice); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
if ($voice) { |
145
|
|
|
|
|
|
|
$voice =~ s/([^0-9A-Za-z_ ])/'%'.unpack('H2',$1)/ge; |
146
|
|
|
|
|
|
|
$voice =~ s/\s/+/g; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
return $voice; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
__END__ |