-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdealscanner
77 lines (64 loc) · 1.39 KB
/
dealscanner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
# dealscanner
# Scans websites for changes in prices
use LWP::Simple;
use Mail::Sendmail;
my $html_output = '/tmp/dealscanner-output-';
$regex_dell = qr/<div class=\"para_marketingprice_(simple|to)\">\$([\.,0-9]+)</;
my @names = (
'Dell 30" LCD',
'Dell 24" LCD',
);
my @addresses = (
'http://accessories.us.dell.com/sna/ProductDetail.aspx?sku=222-0863&c=ca&l=en&cs=cadhs1&brandid=56&page=productlisting.aspx',
'http://accessories.us.dell.com/sna/productdetail.aspx?c=ca&l=en&s=dhs&cs=CADHS1&sku=320-4335',
);
my @old_prices = (
2199.00,
949.00,
);
my @regexs = (
$regex_dell,
$regex_dell,
);
my $message = "";
# Download the web pages with prices
sub get_pages
{
for ($i = 0; $i < $#addresses+1; $i++)
{
$pages[$i] = get($addresses[$i]);
$message .= "Failed to acquire page for \"$names[$i]\"\n\n" unless defined $pages[$i];
}
}
# Extract the prices
sub find_prices
{
for ($i = 0; $i < $#addresses+1; $i++)
{
if ($pages[$i] =~ /$regexs[$i]/gc)
{
$new_prices[$i] = "$2";
$new_prices[$i] =~ s/,//g;
}
else
{
$new_prices[$i] = $old_prices[$i];
$message = "${message}$names[$i]: Price not found\n\n";
}
if ($old_prices[$i] != $new_prices[$i])
{
$message .= "$names[$i]: \$$old_prices[$i] => \$$new_prices[$i]\nURL: $addresses[$i]\n\n";
}
}
}
get_pages;
find_prices;
if ($message ne '')
{
print "$message";
}
else
{
print "No price changes\n";
}