line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BusyBird::Filter::Twitter; |
2
|
1
|
|
|
1
|
|
30429
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
4
|
1
|
|
|
1
|
|
415
|
use BusyBird::DateTime::Format; |
|
1
|
|
|
|
|
122106
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
402
|
use BusyBird::Util qw(split_with_entities vivifiable_as); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
6
|
1
|
|
|
1
|
|
342
|
use BusyBird::Filter qw(filter_map); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
718
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
{ |
10
|
|
|
|
|
|
|
my @names = qw(all search_status status_id unescape); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
12
|
|
|
|
|
|
|
transform => [map { "trans_twitter_$_" } @names], |
13
|
|
|
|
|
|
|
filter => [map { "filter_twitter_$_" } @names] |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
BusyBird::Util::export_ok_all_tags; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $DATETIME_FORMATTER = 'BusyBird::DateTime::Format'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %_SEARCH_KEY_MAP = ( |
22
|
|
|
|
|
|
|
id => 'from_user_id', |
23
|
|
|
|
|
|
|
id_str => 'from_user_id_str', |
24
|
|
|
|
|
|
|
screen_name => 'from_user', |
25
|
|
|
|
|
|
|
profile_image_url => 'profile_image_url', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub trans_twitter_search_status { |
29
|
20
|
|
|
20
|
1
|
806
|
my ($status) = @_; |
30
|
20
|
100
|
|
|
|
49
|
if(exists($status->{created_at})) { |
31
|
4
|
|
|
|
|
17
|
$status->{created_at} = $DATETIME_FORMATTER->format_datetime( |
32
|
|
|
|
|
|
|
$DATETIME_FORMATTER->parse_datetime($status->{created_at}) |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
20
|
100
|
|
|
|
4827
|
return $status if defined $status->{user}; |
36
|
16
|
|
|
|
|
26
|
$status->{user} = {}; |
37
|
16
|
|
|
|
|
36
|
foreach my $new_id_key (keys %_SEARCH_KEY_MAP) { |
38
|
64
|
|
|
|
|
58
|
my $orig_id_key = $_SEARCH_KEY_MAP{$new_id_key}; |
39
|
64
|
100
|
|
|
|
132
|
$status->{user}{$new_id_key} = delete $status->{$orig_id_key} if exists $status->{$orig_id_key}; |
40
|
|
|
|
|
|
|
} |
41
|
16
|
|
|
|
|
41
|
return $status; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $FILTER_SEARCH = filter_map \&trans_twitter_search_status; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub filter_twitter_search_status { |
47
|
1
|
|
|
1
|
1
|
4
|
return $FILTER_SEARCH; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub trans_twitter_status_id { |
51
|
22
|
|
|
22
|
1
|
1399
|
my ($status, $api_url) = @_; |
52
|
22
|
100
|
|
|
|
49
|
$api_url = "https://api.twitter.com/1.1/" if not defined $api_url; |
53
|
22
|
|
|
|
|
80
|
$api_url =~ s|/+$||; |
54
|
22
|
|
|
|
|
30
|
foreach my $key (qw(id id_str in_reply_to_status_id in_reply_to_status_id_str)) { |
55
|
88
|
100
|
|
|
|
180
|
next if not defined $status->{$key}; |
56
|
30
|
100
|
66
|
|
|
74
|
if(vivifiable_as($status->{busybird}, "HASH") |
57
|
|
|
|
|
|
|
&& vivifiable_as($status->{busybird}{original}, "HASH")) { |
58
|
27
|
|
|
|
|
53
|
$status->{busybird}{original}{$key} = $status->{$key}; |
59
|
|
|
|
|
|
|
} |
60
|
30
|
|
|
|
|
86
|
$status->{$key} = "$api_url/statuses/show/" . $status->{$key} . ".json"; |
61
|
|
|
|
|
|
|
} |
62
|
22
|
|
|
|
|
64
|
return $status; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub filter_twitter_status_id { |
66
|
2
|
|
|
2
|
1
|
2
|
my ($api_url) = @_; |
67
|
2
|
|
|
2
|
|
12
|
return filter_map sub { trans_twitter_status_id($_[0], $api_url) }; |
|
2
|
|
|
|
|
6
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub trans_twitter_unescape { |
71
|
29
|
|
|
29
|
1
|
3920
|
my ($status) = @_; |
72
|
29
|
100
|
|
|
|
67
|
if(ref($status->{retweeted_status}) eq "HASH") { |
73
|
3
|
|
|
|
|
8
|
trans_twitter_unescape($status->{retweeted_status}); |
74
|
|
|
|
|
|
|
} |
75
|
29
|
100
|
|
|
|
50
|
if(!defined($status->{text})) { |
76
|
19
|
|
|
|
|
72
|
return $status; |
77
|
|
|
|
|
|
|
} |
78
|
10
|
|
|
|
|
26
|
my $segments = split_with_entities($status->{text}, $status->{entities}); |
79
|
10
|
|
|
|
|
12
|
my $new_text = ""; |
80
|
10
|
|
|
|
|
13
|
my %new_entities = (); |
81
|
10
|
100
|
|
|
|
52
|
if(ref($status->{entities}) eq 'HASH') { |
82
|
6
|
|
|
|
|
4
|
%new_entities = map { $_ => [] } keys %{$status->{entities}}; |
|
24
|
|
|
|
|
34
|
|
|
6
|
|
|
|
|
13
|
|
83
|
|
|
|
|
|
|
} |
84
|
10
|
|
|
|
|
17
|
foreach my $segment (@$segments) { |
85
|
34
|
|
|
|
|
89
|
$segment->{text} =~ s/</
|
86
|
34
|
|
|
|
|
35
|
$segment->{text} =~ s/>/>/g; |
87
|
34
|
|
|
|
|
31
|
$segment->{text} =~ s/"/"/g; |
88
|
34
|
|
|
|
|
44
|
$segment->{text} =~ s/&/&/g; |
89
|
34
|
100
|
|
|
|
58
|
if(ref($segment->{entity}) eq "HASH") { |
90
|
14
|
50
|
|
|
|
27
|
if(vivifiable_as($segment->{entity}{indices}, "ARRAY")) { |
91
|
14
|
|
|
|
|
19
|
$segment->{entity}{indices}[0] = length($new_text); |
92
|
14
|
|
|
|
|
25
|
$segment->{entity}{indices}[1] = $segment->{entity}{indices}[0] + length($segment->{text}); |
93
|
|
|
|
|
|
|
} |
94
|
14
|
|
|
|
|
12
|
push(@{$new_entities{$segment->{type}}}, $segment->{entity}); |
|
14
|
|
|
|
|
20
|
|
95
|
|
|
|
|
|
|
} |
96
|
34
|
|
|
|
|
50
|
$new_text .= $segment->{text}; |
97
|
|
|
|
|
|
|
} |
98
|
10
|
|
|
|
|
13
|
$status->{text} = $new_text; |
99
|
10
|
100
|
|
|
|
16
|
if(defined($status->{entities})) { |
100
|
6
|
|
|
|
|
7
|
$status->{entities} = \%new_entities; |
101
|
|
|
|
|
|
|
} |
102
|
10
|
|
|
|
|
65
|
return $status; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $FILTER_UNESCAPE = filter_map \&trans_twitter_unescape; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub filter_twitter_unescape { |
108
|
4
|
|
|
4
|
1
|
9
|
return $FILTER_UNESCAPE; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub trans_twitter_all { |
112
|
18
|
|
|
18
|
1
|
1572
|
my ($status, $api_url) = @_; |
113
|
18
|
|
|
|
|
27
|
return trans_twitter_unescape( |
114
|
|
|
|
|
|
|
trans_twitter_status_id( |
115
|
|
|
|
|
|
|
trans_twitter_search_status($status), |
116
|
|
|
|
|
|
|
$api_url |
117
|
|
|
|
|
|
|
) |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub filter_twitter_all { |
122
|
3
|
|
|
3
|
1
|
2397
|
my ($api_url) = @_; |
123
|
3
|
|
|
16
|
|
18
|
return filter_map sub { trans_twitter_all($_[0], $api_url) }; |
|
16
|
|
|
|
|
47
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
__END__ |