/[corp]/esi/filter3.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

Diff of /esi/filter3.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Tue Sep 3 08:00:08 2002 UTC revision 1.2 by dpavlin, Tue Sep 3 08:23:08 2002 UTC
# Line 5  use strict; Line 5  use strict;
5  use DBI;  use DBI;
6  use HTML::TreeBuilder;  use HTML::TreeBuilder;
7    
8  my $debug=1;  my $debug=0;
9    
10  my $url = 'http://custom.marketwatch.com/custom/alliance/ftmw/invrel.asp?siteid=!plivadd-0773-4F6D-DHID-QN1112NFTD0X&symb=PLVD';  my $url = 'http://custom.marketwatch.com/custom/alliance/ftmw/invrel.asp?siteid=!plivadd-0773-4F6D-DHID-QN1112NFTD0X&symb=PLVD';
11    
# Line 22  sub print_debug { Line 22  sub print_debug {
22  }  }
23    
24  sub print_val {  sub print_val {
         return if (! $debug);  
25          foreach (keys %val) {          foreach (keys %val) {
26                  print "$_: $val{$_}\n";                  print "$_: $val{$_}\n";
27          }          }
# Line 42  $ua->proxy(['http', 'ftp'], 'http://prox Line 41  $ua->proxy(['http', 'ftp'], 'http://prox
41  my $close_time='21:21:21 CET';  my $close_time='21:21:21 CET';
42    
43  sub insert {  sub insert {
44            # fix UNCH to 0
45            foreach (keys %val) {
46                    $val{$_} =~ s/^\s+//;
47                    $val{$_} =~ s/\s+$//;
48                    $val{$_} = 0 if ($val{$_} eq "UNCH");
49            }
50    
51          my $sth = $dbh->prepare("select count(date) from stocks where date='".$val{date}."'");          my $sth = $dbh->prepare("select count(date) from stocks where date='".$val{date}."'");
52          $sth->execute();          $sth->execute();
53          my ($nr) = $sth->fetchrow_array;          my ($nr) = $sth->fetchrow_array;
# Line 49  sub insert { Line 55  sub insert {
55                  my $sql="insert into stocks values ('$val{date}','LSE',$val{curr},$val{change},$val{high},$val{low},$val{open})";                  my $sql="insert into stocks values ('$val{date}','LSE',$val{curr},$val{change},$val{high},$val{low},$val{open})";
56                  $sql=~s/,\+(\d)/,$1/g;  # nuke + which pgsql doesn't like                  $sql=~s/,\+(\d)/,$1/g;  # nuke + which pgsql doesn't like
57                  if ($sql =~ m,n/a,i) {                  if ($sql =~ m,n/a,i) {
58                            print("undefined values found. not inserting in db [$sql]");
59                          print_val();                          print_val();
                         print_debug("undefined values found. not inserting in db");  
60                  } else {                  } else {
61                          $dbh->do("$sql") || die "$sql\n".$DBI::errstr;                          $dbh->do("$sql") || die "$sql\n".$DBI::errstr;
62                  }                  }
# Line 63  sub insert { Line 69  sub insert {
69  my $req = HTTP::Request->new(GET => $url);  my $req = HTTP::Request->new(GET => $url);
70  my $tree = HTML::TreeBuilder->new;  my $tree = HTML::TreeBuilder->new;
71    
72  #my $res = $ua->request($req);  my $res = $ua->request($req);
73  #if ($res->is_success) {  if ($res->is_success) {
74  #       print_debug("html: ".$res->content."\n");          print_debug("html: ".$res->content."\n");
75  #       $tree->parse($res->content) || die "can't parse html file!";          $tree->parse($res->content) || die "can't parse html file!";
76    
77  if (1) {  #       $tree->parse_file("out-without_proxy") || die "can't parse html file!";
         $tree->parse_file("out-without_proxy") || die "can't parse html file!";  
78    
79          # find date          # find date
80          my $t = $tree;          my $t = $tree;
# Line 121  if (1) { Line 126  if (1) {
126          warn "can't fetch stock data";          warn "can't fetch stock data";
127  }  }
128    
129  print_val();  print_val() if ($debug);
130    
131  $dbh->disconnect;  $dbh->disconnect;
132    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.26