Permalink
Browse files

Add unique key.

  • Loading branch information...
tupinek committed Aug 2, 2014
1 parent 0cbc34a commit 871824d7c43772231c7d5fab3941df3e8c38d095
Showing with 20 additions and 0 deletions.
  1. +20 −0 scraper.pl
View
@@ -35,6 +35,7 @@
my $root = get_root($base_uri);
# Look for items.
my $key = key();
my @table = $root->find_by_tag_name('table');
my $year = 2012;
foreach my $table (@table) {
@@ -47,7 +48,9 @@
($cena_bez_dph, my $poznamka_k_cene)
= clean_price($cena_bez_dph);
print "- $year: ".encode_utf8($nazev)."\n";
$key++;
$dt->insert({
'Klic' => $key,
'Rok' => $year,
'Odbor' => $odbor,
'Nazev' => $nazev,
@@ -105,3 +108,20 @@ sub remove_trailing {
${$string_sr} =~ s/\s*$//ms;
return;
}
# Get key.
sub key {
my $ret_ar = eval {
$dt->execute('SELECT MAX(Klic) FROM data');
};
my $key;
if ($EVAL_ERROR || ! @{$ret_ar} || ! exists $ret_ar->[0]->{'max(klic)'}
|| ! defined $ret_ar->[0]->{'max(klic)'}
|| $ret_ar->[0]->{'max(klic)'} == 0) {
$key = 0;
} else {
$key = $ret_ar->[0]->{'max(klic)'};
}
return $key;
}

0 comments on commit 871824d

Please sign in to comment.