Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add countries correctly in scanbot #6014

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}) {
alexgarel marked this conversation as resolved.
Show resolved Hide resolved
$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