App-Chart

 view release on metacpan or  search on metacpan

devel/convert-scm.pl  view on Meta::CPAN

        $sth->execute ('favourites', $pos, $list->[$pos]);
        $sth->finish();
      }

    } elsif ($key eq 'lme-username'
             || $key eq 'lme-password'
             || $key eq 'yahoo-quote-host'
             || $key eq 'yahoo-quote-timezone'
             || $key eq 'commsec-data-url'
             || $key eq 'commsec-enabled') {
      my ($key, $value) = @$form;
      if ($key eq 'commsec-enabled') {
        $key = 'commsec-enable';
        if ($value eq 'yes') { $value = 1; }
        if ($value eq 'no') { $value = 0; }
      }
      my $sth = $nbh->prepare_cached
        ('INSERT INTO preference (key, value) VALUES (?,?)');
      $sth->execute ($key, $value);
      $sth->finish();

    } else {
      print "(skip $key)\n";
    }
  }
}

sub convert_historical {
  require App::Chart::Gtk2::Symlist::Historical;
  require App::Chart::Gtk2::Symlist::All;
  my $historical_symlist = App::Chart::Gtk2::Symlist::Historical->instance;
  my $all_symlist = App::Chart::Gtk2::Symlist::All->instance;

  my $filename = "$ENV{HOME}/Chart/cache/historical-symbols";
  if (! -e $filename) { return; }
  my $content = File::Slurp::slurp ($filename);
  $content =~ s/\#f/""/g;
  my $forms = Lisp::Reader::lisp_read($content);

  my $sth = $dbh->prepare_cached
    ('UPDATE info SET historical=1 WHERE symbol=?');
  foreach my $symbol (@{$forms->[0]}) {
    if (App::Chart::Database->symbol_exists ($symbol)) {
      print "historical $symbol\n";
      $sth->execute ($symbol);
      $sth->finish;

      $historical_symlist->insert_symbol ($symbol);
    }
  }

  foreach my $symbol (App::Chart::Database->symbols_list()) {
    if (! App::Chart::Database->symbol_is_historical ($symbol)) {
      $all_symlist->insert_symbol ($symbol);
    }
  }
}

$dbh->begin_work;
$nbh->begin_work;
$dbh->do ('PRAGMA synchronous = OFF');
$dbh->do ('PRAGMA cache_size = 20000'); # of 1.5k pages, is 30Mb

convert_prefs();

#convert_notes ('BHP.AX','BBW.AX','ERA.AX','TEL.NZ');
convert_notes (directory_files ("$ENV{HOME}/Chart/notes"));

convert_intraday ();

#convert_data ('TEL.NZ','FPA.NZ','BHP.AX','IPG.AX');
convert_data (directory_files ("$ENV{HOME}/Chart/data"));

convert_historical;

#convert_latest ('BBW.AX','ERA.AX');
convert_latest (directory_files ("$ENV{HOME}/Chart/cache/latest"));

$dbh->commit;
$nbh->commit;
App::Chart::DBI->disconnect();

system 'ls -l ~/Chart/database.sqdb ~/Chart/notes.sqdb';
exit 0;



# Local variables:
# compile-command: "rm ~/Chart/database.sqdb ~/Chart/notes.sqdb; perl ~/pchart/devel/convert-scm.pl"
# End:



( run in 1.701 second using v1.01-cache-2.11-cpan-df04353d9ac )