Type Country1 Order Country2 Product Cu 1995_Jan Cu 1995_Feb Cu 1995_Mar Cu 1995_Apr Cu 1995_May
Production World Total 132 World Total Blister 4633463 34634636 3463463 567567 4574757
Production World Total 132 World Total Ores CNT 6546456 3463463 3463447 56745346 5676575
Production World Total 132 World Total Ref Cu 453453 3463463 567564 658567567 5675675
Stocks Democratic Republic Congo 5 Democratic Republic Congo Ref Cu 34634 34634 4567457 657547 67856
Expand|Select|Wrap|Line Numbers
- # Variable initialization.
- my $data_dir = $DATA . '/in/';
- my $file = 'prod1.xls';
- my $dat = 'datfile.dat';
- my $data = '/ABCD/';
- my $gaa_daily = $data . 'daily/';
- my $xy = "$data_dir$file";
- &excel();
- &sftp();
- print "hi there";
- sub excel {
- use Spreadsheet::ParseExcel;
- my $oExcel = new Spreadsheet::ParseExcel;
- my $field1 = "Production";
- my $field2 = "World Total";
- my $field3 = "Ref Cu";
- my $excel = Spreadsheet::ParseExcel::Workbook->Parse("$xy");
- open (FILE, ">$data_dir$dat") or die "Cannot creat file: $!\n";
- for my $sheet (@{$excel->{Worksheet}}) {
- for my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
- my $cell = $sheet->{Cells}[$row][1];
- if ($sheet->{Cells}[$row][0]->{Val} eq $field1 && $sheet->{Cells}[$row][1]->{Val} eq $field2 && $sheet->{Cells}[$row][4]->{Val} eq $field3) {
- my $last_col = $sheet->{MaxCol} || 0;
- for (5..$last_col) {
- my $cell1 = $sheet->{Cells}[0][$_]->{Val};
- my $cell2 = $sheet->{Cells}[$row][$_]->{Val};
- if (($cell2 =~ /([-]\d{0,5})/g) || ($cell2 =~ /(^\d\d\d\d\d$)/g)) {
- exit 0;
- }
- print FILE "WBMS $cell1 Cu_prod $cell2\n";
- }
- }
- }
- }
- close FILE;
- }
- sub sftp {
- $ftp_cmds = "";
- $tempfile = $data_dir . $dat;
- $ftp_cmds .= "put " . "$tempfile" ." ". $gaa_daily.$dat."\n";
- # COnvert from unix to DOS format
- $convert_filelist[0]='WBMS.dat';
- $rc=toolkit::convert2dos("$data_dir", \@convert_filelist);
- # Perform the sftp
- # Add retry sftp once
- $rc = toolkit::sftp($ftp_cmds);
- if ($rc != 0) {
- print("\n***SFTP failed on the first attempt. Retrying. ***\n");
- $rc = toolkit::sftp($ftp_cmds);
- }
- if ($rc != 0) {
- print("\nError unable to retrieve the raw Datastream files for processing.");
- exit -1;
- } else {
- print ("\nSFTP sucessfully retrived raw Datastream files.");
- }
- }