From 65bba562529fc495dfe8e8814518eb661eef8934 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 11 Mar 2015 15:50:00 +0900 Subject: [PATCH] Log review accesses --- client/scripts/search.js | 2 +- scrape/build_db.js | 2 +- server/search.js | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client/scripts/search.js b/client/scripts/search.js index e9f9c42..c39cd0a 100644 --- a/client/scripts/search.js +++ b/client/scripts/search.js @@ -43,7 +43,7 @@ $('#profileDlg').on('hidden.bs.modal', onSearch); window.accessReview = function(id) { - $.getJSON('/access', {id: id}, function(results) { + $.getJSON('/access', {id: id, profile: localStorage}, function(results) { if (results.success) { location.replace(results.url); } diff --git a/scrape/build_db.js b/scrape/build_db.js index 29d63cd..bdfb998 100755 --- a/scrape/build_db.js +++ b/scrape/build_db.js @@ -90,7 +90,7 @@ conn.query('CREATE TABLE history(date DATETIME NOT NULL, reviewId INT NOT NULL, // conn.query('DROP TABLE IF EXISTS historyGroups'); -conn.query('CREATE TABLE historyGroups(categoryId INT NOT NULL, historyId INT NOT NULL)'); +conn.query('CREATE TABLE historyGroups(categoryId INT NOT NULL, categoryValue FLOAT NOT NULL, historyId INT NOT NULL)'); // diff --git a/server/search.js b/server/search.js index 72158f7..670a079 100644 --- a/server/search.js +++ b/server/search.js @@ -260,6 +260,19 @@ function accessReview(query, callback) { if (results.success) { results.url = 'http://www.tripadvisor.com' + rows[0].url; + + pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) { + if (err) { + throw err; + } + + for (var categoryId in query.profile) { + pool.query( + 'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)', + [categoryId, query.profile[categoryId], info.insertId] + ); + } + }); } callback(results);