#!/usr/bin/perl -w
require
5.005;
use
vars
qw($VERSION $YIND_URL_HEAD $YIND_URL_TAIL)
;
our
$VERSION
=
'1.64_03'
;
my
$YIND_URL_TAIL
=
'&lang=it'
;
sub
methods {
return
(
borsa_italiana
=> \
&borsa_italiana
,
);
}
{
my
@labels
=
qw/name last date isodate volume currency method exchange type
div_yield eps pe year_range open high low close/
;
sub
labels {
return
(
borsa_italiana
=> \
@labels
,
);
}
}
sub
borsa_italiana {
my
$quoter
=
shift
;
my
@bonds
=
@_
;
my
(
%info
,
$reply
,
$url
,
$te
,
$ts
,
$row
,
@cells
,
$ce
);
my
(
$my_date
);
my
$ua
=
$quoter
->user_agent();
foreach
my
$bond
(
@bonds
) {
$url
=
$YIND_URL_HEAD
.
$bond
.
$YIND_URL_TAIL
;
$reply
=
$ua
->get(
$url
);
my
$code
=
$reply
->code;
my
$desc
= HTTP::Status::status_message(
$code
);
my
$headers
=
$reply
->headers_as_string;
my
$body
=
$reply
->content;
$info
{
$bond
,
"symbol"
} =
$bond
;
if
(
$code
== 200 ) {
my
$widget
= scraper {
process
'div.summary-value span.t-text'
,
'val'
=>
'TEXT'
;
};
my
$result
=
$widget
->scrape(
$reply
);
unless
(
exists
$result
->{val}) {
$info
{
$bond
,
'success'
} = 0;
$info
{
$bond
,
'errormsg'
} =
'Failed to find ISIN'
;
next
;
}
my
$value
=
$result
->{val};
$value
=~ s/[^0123456789,]//g;
$value
=~ s/,/./g;
$widget
= scraper {
process
'title'
,
'name'
=>
'TEXT'
;
};
$result
=
$widget
->scrape(
$reply
);
unless
(
exists
$result
->{name}) {
$info
{
$bond
,
'success'
} = 0;
$info
{
$bond
,
'errormsg'
} =
'Failed to find ISIN'
;
next
;
}
my
$name
=
$result
->{name};
$name
=~ s/quotazioni in tempo reale .* Borsa Italiana//g;
$widget
= scraper {
process
'div.summary-fase span.t-text'
,
'dt[]'
=>
'TEXT'
;
};
$result
=
$widget
->scrape(
$reply
);
unless
(
exists
$result
->{dt}) {
$info
{
$bond
,
'success'
} = 0;
$info
{
$bond
,
'errormsg'
} =
'Failed to find ISIN'
;
next
;
}
my
$date
=
$result
->{dt}[1];
$date
=~ s/.
*Contratto
:\ //g;
$date
=~ s/[^0123456789]//g;
my
(
$dd
,
$mm
,
$yy
,
$hh
,
$mi
,
$ss
) =
$date
=~ /^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{1,})([0-9]{2})([0-9]{2})\z/ or
die
;
my
$my_date
=
$dd
.
"."
.
$mm
.
"."
.
$yy
.
" "
.
$hh
.
":"
.
$mi
.
":"
.
$ss
;
$info
{
$bond
,
"success"
} = 1;
$info
{
$bond
,
"exchange"
} =
"Borsa Italiana"
;
$info
{
$bond
,
"method"
} =
"borsa_italiana"
;
$info
{
$bond
,
"name"
} =
$name
;
$info
{
$bond
,
"symbol"
} =
$bond
;
$info
{
$bond
,
"price"
} =
$value
;
$info
{
$bond
,
"last"
} =
$value
;
$info
{
$bond
,
"currency"
} =
"EUR"
;
$quoter
->store_date( \
%info
,
$bond
,
{
eurodate
=>
$my_date
} );
}
else
{
$info
{
$bond
,
"success"
} = 0;
$info
{
$bond
,
"errormsg"
} =
"Error retrieving quote for $bond. Attempt to fetch the URL $url resulted in HTTP response $code ($desc)"
;
}
}
return
wantarray
() ?
%info
: \
%info
;
return
\
%info
;
}
1;