Skip to content

Instantly share code, notes, and snippets.

@paveljurca
Last active November 26, 2017 23:55
Show Gist options
  • Save paveljurca/36c627baf87c253f8896 to your computer and use it in GitHub Desktop.
Save paveljurca/36c627baf87c253f8896 to your computer and use it in GitHub Desktop.
bazar.fotoskoda.cz watchdog
#!/bin/bash
bazaar=$( perl fotoskoda.pl )
# new stuff arrived
if [ "$bazaar" > /dev/null ]; then
# send me an email
echo "$bazaar";
fi;
use strict;
use warnings;
use LWP::UserAgent;
use open qw/:std :utf8/;
use autodie;
#============================
# not saving BLOCKed items
#============================
use constant API
# table, time ordered, 50 per site
=> 'https://bazar.fotoskoda.cz/default.asp?fc=6&ids=000000&kdehle=-1&po=0&pcas=1&pa=2-2&r=50'
;
my $req = HTTP::Request->new(
GET => API, [
User_Agent => 'Googlebot/2.1',
]
);
my $res = LWP::UserAgent->new->request($req);
die q(can't connect) if $res->is_error;
my @bazaar;
my @html = split m|<th>|, $res->decoded_content;
shift @html; # cut the first odd
for (@html) {
# this way match is rather by accident
my ($url) = m|href="([^"]+)|;
$url = 'https://bazar.fotoskoda.cz/' . $url;
my ($item) = m|>([^<]+)</a>|;
my ($state) = m|>Stav ([^<]+)|i;
my $block = m|rezervov| ? 'BLOCK' : '';
my ($price) = m|class="price">([^<]+)|;
push @bazaar,
#sprintf "%-60s %5s | %-8s | %-3s | %s\n",
sprintf "%-60s %s | %-8s | %-3s | %s\n",
( $item, $block, $price, $state, $url )
;
}
# save unique only
my @filter = do {
my @db;
if (-e 'fotoskoda.txt') {
open(my $in, '<:utf8', 'fotoskoda.txt');
@db = <$in>;
}
map {
my $new = $_;
(grep {
my $old = $_;
$new =~ /BLOCK/
or $new eq $old
} @db) ? () : $new
} @bazaar;
};
# no update on delete
if (@filter) {
# write db on new
open(my $out, '>:utf8', 'fotoskoda.txt');
print $out @bazaar;
# print those new added
print @filter;
}
Canon EF 50/1,4 USM | 6 900,- | 1/B | https://bazar.fotoskoda.cz/b960046448-cz-canon-ef-5014-usm
Canon EF 55-200/4,5-5,6 II USM | 2 900,- | 1/B | https://bazar.fotoskoda.cz/b960046449-cz-canon-ef-552004556-ii-usm
Canon EF 70-200/4 L IS USM | 21 500,- | 1/B | https://bazar.fotoskoda.cz/b960045098-cz-canon-ef-702004-l-is-usm
Canon EOS 7D + BG-E7 BLOCK | 14 500,- | 1/B | https://bazar.fotoskoda.cz/b960046446-cz-canon-eos-7d-+-bge7
Canon fotobrašna | 1 400,- | 1/C | https://bazar.fotoskoda.cz/b960046452-cz-canon-fotobrasna
Canon Speedlite 430 EX | 3 900,- | 1/C | https://bazar.fotoskoda.cz/b960046451-cz-canon-speedlite-430-ex
Kenko DG mezikroužky sada 12, 20, 36, mm Canon EF(EF-s) | 2 900,- | 1/B | https://bazar.fotoskoda.cz/b960045096-cz-kenko-dg-mezikrouzky-sada-12-20-36-mm-canon-ef(efs)
makro měch pro Pentax | 800,- | 1/C | https://bazar.fotoskoda.cz/b960046458-cz-makro-mech-pro-pentax
Minolta Hi-Matic F | 700,- | 1/B | https://bazar.fotoskoda.cz/b960046453-cz-minolta-himatic-f
Nikon D3200 | 4 900,- | 1/B | https://bazar.fotoskoda.cz/b960046456-cz-nikon-d3200
Nikon F55 + 28-80/3,5-5,6G BLOCK | 1 500,- | 1/C | https://bazar.fotoskoda.cz/b960046454-cz-nikon-f55-+-28803556g
Nikon ME-1 stereo mikrofon | 1 900,- | 1/B | https://bazar.fotoskoda.cz/b960046450-cz-nikon-me1-stereo-mikrofon
Sigma AF 17-70/2,8-4 DC Macro HSM P | 6 900,- | 1/C | https://bazar.fotoskoda.cz/b960046457-cz-sigma-af-1770284-dc-macro-hsm-p
Tamron AF 28-75/2,8 Macro XR Di ASPH LD C BLOCK | 5 200,- | 1/B | https://bazar.fotoskoda.cz/b960046447-cz-tamron-af-287528-macro-xr-di-asph-ld-c
Unitor makroměch pro Pentax | 1 500,- | 1/C | https://bazar.fotoskoda.cz/b960046459-cz-unitor-makromech-pro-pentax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment