/
server.js
64 lines (48 loc) · 1.92 KB
/
server.js
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
var path = require('path');
var http = require('http');
var express = require('express');
var hbs = require('hbs');
var zillow = new (require('node-zillow'))('X1-ZWz1e1hss309vv_89sjr');
var cheerio = require('cheerio');
var request = require('request');
hbs.registerPartials(__dirname + '/views/partials');
var server = express()
.set('view engine', 'html')
.engine('html', hbs.__express)
.use(express.static(__dirname + '/www'))
.use(express.static(__dirname + '/bower_components'))
.use(express.bodyParser())
server.get('/', function(req,res){
res.render("index.html")
});
server.post('/results', function(req,res){
res.render('summary.html');
// // TODO: only add if actually included in the post
// var params = {
// address: req.body.address.street,
// city: req.body.address.city,
// state: req.body.address.state,
// zip: req.body.address.zip
// }
// // zillow.getDemographics({zip:zip}).then(function(data){
// // var propTax = data.response[0].pages[0].page[0].tables[0].table[0].data[0].attribute[13].values[0].zip[0].value[0]._;
// // });
// zillow.getDeepSearchResults(params).then(function(data){
// var house = data.response[0].results[0].result[0];
// var detailsUrl = house.links[0].homedetails[0];
// request(detailsUrl, function(err,resp,html){
// var $ = cheerio.load(html);
// var annualTax = $('#hdp-tax-history tbody tr:first-of-type td').eq(1).contents().eq(0).text().replace(/\D/g,'');
// // TODO: handle when no estimate (estimate will be empty string)
// var estimate = $('#home-value-wrapper span:contains(Zestimate)').parent().text().replace(/\D/g,'');
// // TODO: compare to potential houses
// console.log(annualTax, estimate);
// });
// });
});
server
.use(express.static(__dirname + '/www'))
.use(express.static(__dirname + '/bower_components'))
var port = process.env.PORT || 3000;
server.listen(port);
console.log(__filename + ' is now listening on port ' + port);