line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Txodds; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22014
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
105
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require HTTP::Request::Common; |
8
|
|
|
|
|
|
|
require LWP::UserAgent; |
9
|
|
|
|
|
|
|
require XML::LibXML::Simple; |
10
|
|
|
|
|
|
|
require Carp; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.69'; |
13
|
1
|
|
50
|
1
|
|
5
|
use constant DEBUG => $ENV{TXODDS_DEBUG} || 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2362
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
|
|
my $class = shift; |
17
|
0
|
|
|
|
|
|
my $self = {@_}; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
0
|
|
|
|
$self->{ua} ||= LWP::UserAgent->new( agent => "TXOdds-agent/$VERSION" ); |
20
|
0
|
|
0
|
|
|
|
$self->{xml} ||= XML::LibXML::Simple->new; |
21
|
0
|
|
|
|
|
|
bless $self, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub odds_feed { |
25
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
26
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/odds/xml.php'; |
27
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
28
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ), |
29
|
|
|
|
|
|
|
ForceArray => 'bookmaker' ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub results_feed { |
33
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
34
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/result/xml.php'; |
35
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
36
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub htcs_feed { |
40
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
41
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/odds/htftcrs.php'; |
42
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
43
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub average_feed { |
47
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
48
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/average/xml.php'; |
49
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
50
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub antepost_feed { |
54
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
55
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/odds/ap.php'; |
56
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
57
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub boid_states { |
61
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
62
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/boid_states.php'; |
63
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
64
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub starting_times { |
68
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
69
|
0
|
|
|
|
|
|
my $url = 'http://txodds.com/feed/starting_times.php'; |
70
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
71
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub moves { |
75
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
76
|
0
|
|
|
|
|
|
my $url = 'http://www.txodds.com/feed/moves/xml.php'; |
77
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
78
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub sports { |
82
|
0
|
|
|
0
|
|
|
my $self = shift; |
83
|
0
|
|
|
|
|
|
my $content = $self->get('http://xml2.txodds.com/feed/sports.php'); |
84
|
0
|
|
|
|
|
|
my $data = $self->parse_xml( $content, ValueAttr => [ 'sport', 'name' ] ); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my %sports; |
87
|
0
|
|
|
|
|
|
foreach (@$data) { |
88
|
0
|
|
|
|
|
|
$sports{ $_->{id} } = $_->{name}; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
return %sports; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub mgroups { |
94
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
95
|
0
|
|
|
|
|
|
my $content = |
96
|
|
|
|
|
|
|
$self->get( 'http://xml2.txodds.com/feed/mgroups.php', \%params ); |
97
|
0
|
|
|
|
|
|
my $data = |
98
|
|
|
|
|
|
|
$self->parse_xml( $content, ValueAttr => [ 'mgroup', 'sportid' ] ); |
99
|
0
|
|
|
|
|
|
my %mgroups; |
100
|
0
|
|
|
|
|
|
foreach (@$data) { |
101
|
0
|
|
|
|
|
|
$mgroups{ $_->{name} } = $_->{sportid}; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
return %mgroups; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub odds_types { |
107
|
0
|
|
|
0
|
|
|
my $self = shift; |
108
|
0
|
|
|
|
|
|
my $content = $self->get('http://xml2.txodds.com/feed/odds_types.php'); |
109
|
0
|
|
|
|
|
|
my $data = $self->parse_xml( $content, ValueAttr => ['type'] ); |
110
|
0
|
0
|
|
|
|
|
unless (@_) { |
111
|
0
|
|
|
|
|
|
my %obj; |
112
|
0
|
|
|
|
|
|
foreach (@$data) { |
113
|
0
|
|
|
|
|
|
$obj{ $_->{ot} } = $_->{name}; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
return \%obj; |
116
|
|
|
|
|
|
|
} |
117
|
0
|
|
|
|
|
|
else { return $data; } |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub offer_amounts { |
121
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
122
|
0
|
|
|
|
|
|
my $content = |
123
|
|
|
|
|
|
|
$self->get( 'http://xml2.txodds.com/feed/offer_amounts.php', \%params ); |
124
|
0
|
|
|
|
|
|
my $data = $self->parse_xml( $content, ValueAttr => ['offer'] ); |
125
|
0
|
|
|
|
|
|
my %obj; |
126
|
0
|
0
|
|
|
|
|
if ( ref $data eq 'ARRAY' ) { |
|
|
0
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
foreach (@$data) { $obj{ $_->{boid} } = $_->{amount}; } |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
elsif ( ref $data eq 'HASH' ) { |
130
|
0
|
|
|
|
|
|
$obj{ $$data{boid} } = $$data{amount}; |
131
|
|
|
|
|
|
|
} |
132
|
0
|
|
|
|
|
|
return \%obj; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub ap_offer_amounts { |
136
|
0
|
|
|
0
|
|
|
my $self = shift; |
137
|
0
|
|
|
|
|
|
my $content = |
138
|
|
|
|
|
|
|
$self->get('http://xml2.txodds.com/feed/ap_offer_amounts.php'); |
139
|
0
|
|
|
|
|
|
my $data = $self->parse_xml( $content, ValueAttr => ['offer'] ); |
140
|
0
|
|
|
|
|
|
return $data; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub deleted_ap_offers { |
144
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
145
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/deleted_ap_offers.php'; |
146
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
147
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub countries { |
151
|
0
|
|
|
0
|
|
|
my $self = shift; |
152
|
0
|
|
|
|
|
|
my $content = $self->get('http://xml2.txodds.com/feed/countries.php'); |
153
|
0
|
|
|
|
|
|
my $data = $self->parse_xml( $content, ValueAttr => ['country'] ); |
154
|
0
|
|
|
|
|
|
return $data; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub competitors { |
158
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
159
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/competitors.php'; |
160
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
161
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ), |
162
|
|
|
|
|
|
|
ValueAttr => ['competitor'] ); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub deleted_peids { |
166
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
167
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/deleted_peids.php'; |
168
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
169
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub deleted_boids { |
173
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
174
|
0
|
|
|
|
|
|
my $url = 'http://xml2.txodds.com/feed/deleted_boids.php'; |
175
|
0
|
|
|
|
|
|
@params{ 'ident', 'passwd' } = get_ident_passwd(); |
176
|
0
|
|
|
|
|
|
return $self->parse_xml( $self->get( $url, \%params ) ); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub groups { |
180
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
181
|
0
|
|
|
|
|
|
my $content = |
182
|
|
|
|
|
|
|
$self->get( 'http://xml2.txodds.com/feed/groups.php', \%params ); |
183
|
0
|
|
|
|
|
|
my $data = $self->parse_xml( $content, ValueAttr => ['group'] ); |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
return $data; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub books { |
189
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
190
|
0
|
|
|
|
|
|
my $content = |
191
|
|
|
|
|
|
|
$self->get( 'http://xml2.txodds.com/feed/books.php', \%params ); |
192
|
0
|
|
|
|
|
|
my $data = $self->parse_xml( $content, ValueAttr => ['bookmaker'] ); |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
return $data; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub xml_schema { |
198
|
0
|
|
|
0
|
|
|
my $self = shift; |
199
|
0
|
|
|
|
|
|
my $content = $self->get('http://xml2.txodds.com/feed/odds/odds.xsd'); |
200
|
0
|
|
|
|
|
|
return $content; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub create_get_request { |
204
|
0
|
|
|
0
|
|
|
my ( $self, $url, $params ) = @_; |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$url = URI->new($url); |
207
|
0
|
|
|
|
|
|
$url->query_form(%$params); |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
HTTP::Request::Common::GET($url); |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub get { |
213
|
0
|
|
|
0
|
|
|
my $self = shift; |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $request = $self->create_get_request(@_); |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
warn "GET>\n" if DEBUG; |
218
|
0
|
|
|
|
|
|
warn $request->as_string if DEBUG; |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
my $response = $self->{ua}->request($request); |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
warn "GET<\n" if DEBUG; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return $response->decoded_content; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub parse_xml { |
228
|
0
|
|
|
0
|
|
|
my ( $self, $xml_string, %options ) = @_; |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
my $obj = $self->{xml}->XMLin( $xml_string, %options ); |
231
|
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
|
Carp::croak( "Wrong responce: " . $xml_string ) unless $obj; |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
return $obj; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub get_ident_passwd { |
238
|
0
|
|
|
0
|
|
|
my $self = shift; |
239
|
0
|
0
|
0
|
|
|
|
Carp::croak( |
240
|
|
|
|
|
|
|
"ident & passwd of http://txodds.com API required for this action") |
241
|
|
|
|
|
|
|
unless ( $self->{ident} && $self->{passwd} ); |
242
|
0
|
|
|
|
|
|
return $self->{ident}, $self->{passwd}; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub clean_obj { |
246
|
0
|
|
|
0
|
|
|
my ( $self, $BadObj ) = @_; |
247
|
0
|
|
|
|
|
|
my %sports = $self->sports(); |
248
|
0
|
|
|
|
|
|
my %mgroups = $self->mgroups(); |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $obj->{'timestamp'} = $BadObj->{'timestamp'}; |
251
|
0
|
|
|
|
|
|
$obj->{time} = $BadObj->{'time'}; |
252
|
0
|
|
|
|
|
|
$obj->{'time'} =~ |
253
|
|
|
|
|
|
|
s/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):\d{2}\+\d{2}:\d{2}/$4:$5 $3-$2-$1/; |
254
|
0
|
|
|
|
|
|
while ( my ( $MatchId, $MatchObj ) = each %{ $BadObj->{match} } ) { |
|
0
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
my $Home = |
256
|
0
|
|
|
|
|
|
$MatchObj->{hteam}->{ each %{ $MatchObj->{hteam} } }->{content}; |
257
|
0
|
|
|
|
|
|
my $Away = |
258
|
0
|
|
|
|
|
|
$MatchObj->{ateam}->{ each %{ $MatchObj->{ateam} } }->{content}; |
259
|
0
|
|
|
|
|
|
my $Group = |
260
|
0
|
|
|
|
|
|
$MatchObj->{group}->{ each %{ $MatchObj->{group} } }->{content}; |
261
|
0
|
|
|
|
|
|
my $MatchTime = $MatchObj->{'time'}; |
262
|
0
|
|
|
|
|
|
$MatchTime =~ |
263
|
|
|
|
|
|
|
s/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):\d{2}\+\d{2}:\d{2}/$4:$5 $3-$2-$1/; |
264
|
0
|
0
|
|
|
|
|
my $Sport = $sports{ $mgroups{$1} } if $Group =~ m/^([A-Z]+).*/; |
265
|
0
|
|
|
|
|
|
$Group =~ s/^[A-Z]+ (.*)/$1/; |
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
%{ $obj->{sport}->{$Sport}->{$Group}->{"$Home - $Away"} } = ( |
|
0
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
MatchTime => $MatchTime, |
269
|
|
|
|
|
|
|
Home => $Home, |
270
|
|
|
|
|
|
|
Away => $Away |
271
|
|
|
|
|
|
|
); |
272
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
while ( my ( $BookmakerName, $BookmakerObj ) = |
|
0
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
each %{ $MatchObj->{bookmaker} } ) |
275
|
|
|
|
|
|
|
{ |
276
|
0
|
|
|
|
|
|
while ( my ( $OfferId, $OfferObj ) = |
|
0
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
each %{ $BookmakerObj->{offer} } ) |
278
|
|
|
|
|
|
|
{ |
279
|
0
|
|
|
|
|
|
my $ot = $OfferObj->{ot}; |
280
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
0
|
|
|
|
|
281
|
|
|
|
|
|
|
$ot == 0 |
282
|
|
|
|
|
|
|
&& ( $OfferObj->{odds}->[0]->{o1} |
283
|
|
|
|
|
|
|
|| $OfferObj->{odds}->[0]->{o2} |
284
|
|
|
|
|
|
|
|| $OfferObj->{odds}->[0]->{o3} ) |
285
|
|
|
|
|
|
|
) |
286
|
|
|
|
|
|
|
{ |
287
|
0
|
|
|
|
|
|
%{ $obj->{sport}->{$Sport}->{$Group}->{"$Home - $Away"} |
|
0
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
->{bookmaker}->{$BookmakerName}->{offer}->{$ot} } = ( |
289
|
|
|
|
|
|
|
1 => $OfferObj->{odds}->[0]->{o1}, |
290
|
|
|
|
|
|
|
x => $OfferObj->{odds}->[0]->{o2}, |
291
|
|
|
|
|
|
|
2 => $OfferObj->{odds}->[0]->{o3} |
292
|
|
|
|
|
|
|
); |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
} |
297
|
0
|
|
|
|
|
|
return $obj; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
__END__ |