commit 580f92aaba9842dfb4d1642090115fb14058d0e1
parent b0743ff93b8074647e69329f87f65dccfedbf062
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Tue, 21 Oct 2014 00:25:37 -0600
html: split html pages and use that for searches
Diffstat:
7 files changed, 119 insertions(+), 109 deletions(-)
diff --git a/html/index.html b/html/index.html
@@ -0,0 +1,38 @@
+[% WRAPPER wrapper.html %]
+ <div class="column">
+ <h1>Welcome</h1>
+
+ <p> Welcome to <em>Price</em><b>Chart</b>, an online service for
+ inter-retailer price comparisons of consumer electronics.
+ Currently <b>[% num_products %]</b> products from
+ <b>[% num_manufacturers %]</b> manufacturers are being tracked
+ across <b>[% num_vendors %]</b> retailers.</p>
+
+ <p> To start using the service, try searching for a product or
+ brand in the search box at the top right. </p>
+
+ <p> <em>Price</em><b>Chart</b> periodically looks up and saves
+ the price information of different products. These prices are
+ aggregated by product into charts. From these charts it can be
+ easily determined which retailer currently has the lowest price
+ for a given product. </p>
+ </div>
+
+ <div class="column">
+ <h1>Motivation</h1>
+
+ <p> <em>Price</em><b>Chart</b> is meant to be a consumer
+ purchasing tool. It is intended to give the consumer insight
+ into retail pricing which they would not normally have. </p>
+
+ <p> A common practice when purchasing something new is <em>price
+ comparison</em>. A consumer decides on a certain product
+ they are interested in and then look around for the best deal.
+ That is what this service 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. </p>
+ </div>
+[% END %]
diff --git a/html/index.tt2 b/html/index.tt2
@@ -1,74 +0,0 @@
-<!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
@@ -2,38 +2,38 @@
clear: both;
}
-.column {
- width: 47%;
- padding-left: 1.5%;
- padding-right 1.5%;
-}
-
fieldset {
border: 0px;
+ float: right;
}
input {
font-size: 1em;
}
-.float_left {
- float: left;
+#footer {
+ text-align: center;
}
-.float_right {
- float: right;
+#title {
+ font-size: 2em;
+ color: black;
+ text-decoration: none;
+ float: left;
}
-.footer {
- text-align: center;
-}
+.column {
+ width: 47%;
+ padding-left: 1.5%;
+ padding-right 1.5%;
-.logo {
- padding-right: 10px;
+ float: left;
}
-.title a {
- font-size: 2em;
- color: black;
- text-decoration: none;
+@media (max-width: 640px) {
+ .column {
+ width: 94%;
+ padding-left: 3%;
+ padding-right: 3%;
+ }
}
diff --git a/html/search.html b/html/search.html
@@ -0,0 +1,8 @@
+[% WRAPPER wrapper.html %]
+ <p>Found <b>[% num_results %]</b> search results for <b>[% query
+ %]</b>:</p>
+
+ [% FOREACH variable IN results %]
+ [% variable %]<br>
+ [% END %]
+[% END %]
diff --git a/html/wrapper.html b/html/wrapper.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width" />
+ <title>PriceChart</title>
+ <link rel="stylesheet" type="text/css" href="/pricechart.css" />
+</head>
+<body>
+ <a id="title" href='/'><em>Price</em><b>Chart</b></a>
+ <form method="post" action="/search.html">
+ <fieldset>
+ <input type="text" name="q" />
+ <input type="submit" value="Search">
+ </fieldset>
+ </form>
+ <hr class="clear_both">
+
+ [% content %]
+
+ <hr class="clear_both">
+ <div id="footer">
+ <a href="mailto:kyle@getaddrinfo.net">Feedback/Donate</a>
+ </div>
+</body>
+</html>
diff --git a/search.pl b/search.pl
@@ -4,6 +4,7 @@ use strict;
use warnings;
use FCGI;
+use Template;
use shared;
@@ -24,25 +25,33 @@ sub sigint
}
$SIG{INT} = \&sigint;
+my $config = {
+ INCLUDE_PATH => "html"
+};
+my $template = Template->new($config);
+
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";
- }
+ # 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%");
+ my $query = "select part_num from products where title like ?";
+ my $products = $dbh->selectcol_arrayref($query, undef, "%$input%");
- print "found " . scalar @$products . " products <br>\n";
+ my $vars = {
+ query => "\"$input\"",
+ num_results => scalar @$products,
+ results => $products
+ };
- for (@$products) {
- print "$_->[2] <br>\n";
+ my $r = $template->process("search.html", $vars);
+ if ($r) {
+ print $template->error();
}
}
diff --git a/site_gen.pl b/site_gen.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+use File::Copy;
use GD::SVG;
use GD::Polyline;
use Template;
@@ -17,7 +18,9 @@ my $log = get_log($cfg, "pricecharts_webgen");
my $config = {
INTERPOLATE => 1,
POST_CHOMP => 1,
- EVAL_PERL => 1
+ EVAL_PERL => 1,
+ INCLUDE_PATH => "html",
+ OUTPUT_PATH => "www/htdocs"
};
my $template = Template->new($config);
@@ -28,16 +31,16 @@ 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 $vendors = keys $cfg->{vendors};
my $vars = {
- vendors => \@vendors,
- manufacturers => scalar @$manuf,
+ num_vendors => $vendors,
+ num_manufacturers => scalar @$manuf,
num_products => scalar @$products
};
-my $input = "html/index.tt2";
-$template->process($input, $vars, "www/htdocs/index.html") || die $template->error();
+$template->process("index.html", $vars, "index.html") || die $template->error();
+copy("html/pricechart.css", "www/htdocs/pricechart.css");
# $query = "select part_num from products";
# my $products = $dbh->selectcol_arrayref($query);