diff options
author | Yorhel <git@yorhel.nl> | 2020-11-04 07:45:23 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-11-04 07:45:29 +0100 |
commit | a795b3ee3dc57c27f59ce9f5c3ac8eccfddedcdb (patch) | |
tree | c53077b80c94a95381b5e93555b438fa7e604de2 | |
parent | db12fda5382fd2b418d77ded9d42fa5b30a39135 (diff) |
Multi::Denpa: Another fix to handle multiplatform releases
(And a silly but not terribly important regex fix)
-rw-r--r-- | lib/Multi/Denpa.pm | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/Multi/Denpa.pm b/lib/Multi/Denpa.pm index e367087c..99c60231 100644 --- a/lib/Multi/Denpa.pm +++ b/lib/Multi/Denpa.pm @@ -37,13 +37,16 @@ sub run { sub data { my($time, $id, $body, $hdr) = @_; my $prefix = sprintf '[%.1fs] %s', $time, $id; - return AE::log warn => "$prefix ERROR: $hdr->{Status} $hdr->{Reason}" if $hdr->{Status} !~ /^[2|404]/; + return AE::log warn => "$prefix ERROR: $hdr->{Status} $hdr->{Reason}" if $hdr->{Status} !~ /^(2|404)/; my $listprice = $body =~ m{<meta property="product:price:amount" content="([^"]+)"} && $1; my $currency = $body =~ m{<meta property="product:price:currency" content="([^"]+)"} && $1; my $availability = $body =~ m{<meta property="product:availability" content="([^"]+)"} && $1; my $sku = $body =~ m{<meta property="product:retailer_item_id" content="([^"]+)"} ? $1 : ''; + # Meta properties aren't set if the product has multiple SKU's (e.g. multi-platform), fall back to some json-ld string. + ($listprice, $currency) = ($1,$2) if !$listprice && $body =~ /"priceSpecification":\{"price":"([^"]+)","priceCurrency":"([^"]+)"/; + if($hdr->{Status} eq '404' || !$listprice || !$availability || $availability ne 'instock') { pg_cmd q{UPDATE shop_denpa SET deadsince = COALESCE(deadsince, NOW()), lastfetch = NOW() WHERE id = $1}, [ $id ]; AE::log info => "$prefix not found or not in stock."; |