|
-
This is it! And I need some additional information about how can I use condition IF under perl language, because I need to use the second URL only for one country Canada (this is financial sites), for others I still should use the old one.
My problem is:
these web pages have the same format, BUT old one has 2 columns - name of countries and rates, the new one has 6 columns - name of countries and 5 columns with rates for 5 days. I need to grab only first column and the sixth colums with the latest date.
My question is:
how should I exchange my code for it?
My code is:
#!/usr/local/bin/perl
print "<--- EURO cron: EXCH --->\n";
{
use Date: ateCalc qw ( calc_new_date ) ;
use HTTP::Request;
use LWP::UserAgent;
&set_date;
print "file is $file\n";
&set_url;
print "url is $url\n";
&get_url;
$number_of_tries = 0;
while ($found eq "FALSE" && $number_of_tries < 50) {
&get_url; # set $found in this function.
sleep 10; # sleep 10 seconds before trying again.
$number_of_tries += 1;
}
}
#
#
#
sub set_url {
$url = "http://www.ny.frb.org/pihome/statistics/forex12.shtml
}
#
#
#
sub set_date {
$yr = `date '+%y'`;
$mth = `date '+%m'`;
$day = `date '+%d'`;
chop ( $yr );
chop ( $mth );
chop ( $day );
$edat_base = $ENV{EDAT_BASE};
$dir = "$edat_base/exch/data/";
$file = $dir . $yr . $mth . $day . ".txt" ;
}
#
#
#
sub get_url {
$ua = new LWP::UserAgent;
#$ua->proxy(http => $ENV{PROXY});
$ua->agent("$0/0.1");
$req = new HTTP::Request 'GET', $url;
$req->header('Accept' => 'text/html');
# send request
$res = $ua->request($req);
# check the outcome
if ($res->is_success) {
$fileout = ">".$file;
print "$fileout\n";
close (FILEOUT);
open (FILEOUT,$fileout);
print FILEOUT $res->content;
$found = 'TRUE';
} else {
print "whoops\n";
$found = 'FALSE';
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|