Skip to content

Commit

Permalink
fix: add countries correctly in scanbot (#6014)
Browse files Browse the repository at this point in the history
* fix: add countries correctly - fixes #4870

* remove useless code
  • Loading branch information
stephanegigandet committed Nov 4, 2021
1 parent 258c20e commit 7dceea2
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions scripts/scanbot.pl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
exit();
}


print STDERR "Running scanbot for year $year\n";

my %codes = ();
Expand Down Expand Up @@ -332,8 +331,6 @@
$source = "producers";
}

$lc = $product_ref->{lc};

$product_ref->{unique_scans_n} = $unique_scans_n + 0;
$product_ref->{scans_n} = $scans_n + 0;

Expand Down Expand Up @@ -379,9 +376,7 @@
}

# Add countries tags based on scans
my $field = 'countries';

my $current_countries = $product_ref->{$field};
my $current_countries = $product_ref->{'countries'};

my %existing = ();
foreach my $countryid (@{$product_ref->{countries_tags}}) {
Expand Down Expand Up @@ -417,7 +412,7 @@
# (codes can be reused by different companies in different countries)
if (($add_countries) and ($code !~ /^(02|2)/) and (not exists $existing{$country})) {
print "- adding $country to $product_ref->{countries}\n";
$product_ref->{countries} .= ", $country";
add_tags_to_field($product_ref, "en", "countries", $country);
$bot .= "+$country ";
$added_countries++;
$added_countries_list .= $country .',';
Expand All @@ -431,32 +426,10 @@
}
}

if ($product_ref->{$field} ne $current_countries) {
if ($added_countries_list ne "") {
$product_ref->{"countries_beforescanbot"} = $current_countries;
$changed_products++;

if ($product_ref->{$field} =~ /^, /) {
$product_ref->{$field} = $';
}

if (defined $taxonomy_fields{$field}) {
$product_ref->{$field . "_hierarchy" } = [ gen_tags_hierarchy_taxonomy($lc, $field, $product_ref->{$field}) ];
$product_ref->{$field . "_tags" } = [];
foreach my $tag (@{$product_ref->{$field . "_hierarchy" }}) {
push @{$product_ref->{$field . "_tags" }}, get_taxonomyid($lc, $tag);
}
}

if (defined $hierarchy_fields{$field}) {
$product_ref->{$field . "_hierarchy" } = [ gen_tags_hierarchy($field, $product_ref->{$field}) ];
$product_ref->{$field . "_tags" } = [];
foreach my $tag (@{$product_ref->{$field . "_hierarchy" }}) {
if (get_fileid($tag) ne '') {
push @{$product_ref->{$field . "_tags" }}, get_fileid($tag);
}
}
}

my $comment = $bot;

if (0) {
Expand Down Expand Up @@ -496,8 +469,7 @@
}
}

$User_id = 'scanbot';
store_product($product_ref, $comment);
store_product('scanbot', $product_ref, $comment);
}
else {
print "updating scan count for $code\n";
Expand Down

0 comments on commit 7dceea2

Please sign in to comment.