/[corp]/esi/filter2.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /esi/filter2.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Wed Feb 6 13:01:24 2002 UTC (22 years, 3 months ago) by dpavlin
Branch: MAIN
Changes since 1.2: +1 -1 lines
File MIME type: text/plain
fix date

1 dpavlin 1.1 #!/usr/local/bin/perl -w
2    
3     use LWP::UserAgent;
4     use strict;
5     use DBI;
6    
7     my $debug=0;
8    
9     $debug++ if (lc($ARGV[0]) eq "-d");
10    
11     sub print_debug {
12     return if (! $debug);
13     open(DEBUG,">> debug") || warn "can't open debug file!";
14     print DEBUG "###",@_;
15     print @_;
16     close(DEBUG);
17     }
18    
19     print_debug("debug level $debug");
20    
21     my $dbh = DBI->connect("DBI:Pg:dbname=corp","","") || die $DBI::errstr;
22    
23     my $ua = new LWP::UserAgent;
24     $ua->agent("pliva_harvester 0.0");
25     $ua->timeout(60);
26     $ua->env_proxy();
27     $ua->proxy(['http', 'ftp'], 'http://proxy.pliva.hr:8080/');
28    
29     my @val;
30    
31     my $close_time='21:21:21 CET';
32    
33     sub insert {
34 dpavlin 1.2 my ($date,$curr,$change,$change_pcnt,$high,$low,$open) = @val;
35     my $sql="insert into stocks values ('$date','LSE',$curr,$change,$high,$low,$open)";
36 dpavlin 1.1 $sql=~s/,\+(\d)/,$1/g; # nuke + which pgsql doesn't like
37     $dbh->do("$sql") || die "$sql\n".$DBI::errstr;
38     print_debug("sql: $sql\n");
39     }
40    
41     my $req = HTTP::Request->new(GET =>'http://custom.marketwatch.com/custom/alliance/ftmw/invrel.asp?siteid=!plivadd-0773-4F6D-DHID-QN1112NFTD0X&symb=PLVD');
42    
43     my $res = $ua->request($req);
44     if ($res->is_success) {
45     print_debug("html: ".$res->content."\n");
46     foreach (split(/[\n\r]+/, $res->content)) {
47     chomp;
48     print_debug("line: $_\n");
49     if (m,class="ft-quotedate">(\d+:\d+) (\d+)/(\d+)/(\d+),i) {
50 dpavlin 1.3 my ($time,$dd,$mm,$yy) = ($1,$2,$3,$4);
51 dpavlin 1.1 my $date=($yy+2000)."-$mm-$dd";
52     print_debug("time: $time date: $date");
53     insert() if (@val);
54     undef @val;
55     push @val,"$date $time";
56     $dbh->do("delete from stocks where date='$date $close_time'");
57     }
58     if (m,class="ft-quote[^"]+".*<nobr>(\d+\.\d+)</nobr>,i) {
59 dpavlin 1.2 push @val,$1;
60     print_debug("val: $1");
61     } elsif (m,<nobr>([+-]*\d+\.\d+)</nobr>,i) {
62 dpavlin 1.1 push @val,$1;
63     print_debug("val: $1");
64     }
65    
66     }
67     insert();
68     } else {
69     warn "can't fetch stock data";
70     }
71    
72     $dbh->disconnect;

  ViewVC Help
Powered by ViewVC 1.1.26