pricecharts

track prices of consumer electronics
Log | Files | Refs | README

commit b0743ff93b8074647e69329f87f65dccfedbf062
parent 9c1e0ab57af908c4b9890bd37d421b7404d3e8ca
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Mon, 20 Oct 2014 02:58:47 -0600

add new tools for fcgi searching and www generation

Diffstat:
Ahtml/index.tt2 | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ahtml/pricechart.css | 39+++++++++++++++++++++++++++++++++++++++
Asearch.pl | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Asite_gen.pl | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 234 insertions(+), 0 deletions(-)

diff --git a/html/index.tt2 b/html/index.tt2 @@ -0,0 +1,74 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title>PriceCharts</title> + <link rel="stylesheet" type="text/css" href="/pricechart.css" /> +</head> +<body> + <div class="float_left title"> + <a href='/'><em>Price</em><b>Charts</b></a> + </div> + <div class="float_right"> + <form method="post" action="/search.html"> + <fieldset> + <input type="text" name="q" /> + <input type="submit" value="Search"> + </fieldset> + </form> + </div> + + <hr class="clear_both"> + <div class="float_left column"> + <h1>What</h1> + + <p> Welcome to <b>PriceCharts</b>, a place to do inter-retailer + price comparisons to ensure that products are bought at their + lowest possible price. </p> + + <p> <b>PriceCharts</b> periodically looks up and saves product + price information and then displays it as a chart. From the + chart it is easily determined which retailer has the current + lowest price and also how the price trends over time. Currently + <b>[% num_products %]</b> products from <b>[% manufacturers %] + </b> manufacturers are being tracked. </p> + + <p> The following retailers are included: + <ul> + [% FOREACH variable IN vendors %] + <li>[% variable %] + [% END %] + + </ul> + </p> + </div> + + <div class="float_left column"> + <h1>Why</h1> + + <p> <b>PriceCharts</b> is meant to be a consumers purchasing + tool. It is intended to give the consumer insight into retail + pricing of products which they would not normally have. </p> + + <p> A well known practice when looking to purchase something new + is <em>price comparison</em>. A purchaser decides on a certain + make and model that they want and then look at the different + retailers in their area to find the one with the lowest price. + That is what this website does. It automates <em>price + comparisons</em>. </p> + + <p> This is important because the price difference between + different retailers for the same product is often hundreds of + dollars if not more. One glance at the price chart for the + product will tell you not only the current best retailer to buy + the product from but also historically who has had the best + price. </p> + + </div> + <hr class="clear_both"> + + <div class="footer"> + <a href="mailto:kyle@getaddrinfo.net">Feedback/Donate</a> + </div> +</body> +</html> diff --git a/html/pricechart.css b/html/pricechart.css @@ -0,0 +1,39 @@ +.clear_both { + clear: both; +} + +.column { + width: 47%; + padding-left: 1.5%; + padding-right 1.5%; +} + +fieldset { + border: 0px; +} + +input { + font-size: 1em; +} + +.float_left { + float: left; +} + +.float_right { + float: right; +} + +.footer { + text-align: center; +} + +.logo { + padding-right: 10px; +} + +.title a { + font-size: 2em; + color: black; + text-decoration: none; +} diff --git a/search.pl b/search.pl @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use FCGI; + +use shared; + +my $cfg = get_config(); +my $dbh = get_dbh($cfg); + +mkdir "$cfg->{general}{var}/www/run"; +my $socket_path = "$cfg->{general}{var}/www/run/search.sock"; + +my $socket = FCGI::OpenSocket($socket_path, 1024); +my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, + $socket, FCGI::FAIL_ACCEPT_ON_INTR); + +chmod 0777, $socket_path; +sub sigint +{ + $request->LastCall(); +} +$SIG{INT} = \&sigint; + +while ($request->Accept() >= 0) { + print "Content-Type: text/html\r\n\r\n"; + print "Hello, World!<br>\n"; + + for (sort keys %ENV) { + print "$_: $ENV{$_} <br>\n"; + } + + read(STDIN, my $input, $ENV{CONTENT_LENGTH}); + (undef, $input) = split("=", $input); + print "querying for: $input <br>\n"; + + my $query = "select * from products where title like ?"; + my $products = $dbh->selectall_arrayref($query, undef, "%$input%"); + + print "found " . scalar @$products . " products <br>\n"; + + for (@$products) { + print "$_->[2] <br>\n"; + } +} + +FCGI::CloseSocket($socket); +$dbh->disconnect(); diff --git a/site_gen.pl b/site_gen.pl @@ -0,0 +1,71 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use GD::SVG; +use GD::Polyline; +use Template; +use POSIX; + +use shared; + +my $cfg = get_config(); +my $dbh = get_dbh($cfg); +my $log = get_log($cfg, "pricecharts_webgen"); + +my $config = { + INTERPOLATE => 1, + POST_CHOMP => 1, + EVAL_PERL => 1 +}; + +my $template = Template->new($config); + +my $query = "select distinct brand from products"; +my $manuf = $dbh->selectcol_arrayref($query); + +$query = "select part_num from products"; +my $products = $dbh->selectcol_arrayref($query); + +my @vendors = sort keys $cfg->{vendors}; + +my $vars = { + vendors => \@vendors, + manufacturers => scalar @$manuf, + num_products => scalar @$products +}; + +my $input = "html/index.tt2"; +$template->process($input, $vars, "www/htdocs/index.html") || die $template->error(); + +# $query = "select part_num from products"; +# my $products = $dbh->selectcol_arrayref($query); + +print $log strftime "%b %e %Y %H:%M ", localtime; + +if ($args{p}) { + gen_chart($args{p}); + print $log "$args{p} generated\n"; +} +else { + gen_chart($_) for (@$products); + print $log scalar(@$products) . " products generated\n"; +} + +sub gen_chart +{ + my $part_num = shift; + vprint("$part_num:\n"); + + my $image = new GD::SVG::Image(800, 200); + my $polyline = new GD::Polyline; + + $query = "select * from prices where part_num = ?"; + my $prices = $dbh->selectall_arrayref($query, undef, $part_num); + + vprintf("\t# prices = %i\n", scalar @$prices); +} + +close $log; +$dbh->disconnect();