1

Fixing interpreter name, creating database

This commit is contained in:
Alex Yatskov 2014-09-16 16:27:27 +09:00
parent 2b3dd0b13a
commit 6a57a825f1
3 changed files with 133 additions and 1 deletions

52
scrape/db.js Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env node
var mysql = require('mysql');
var data = require('./data.json');
var conn = mysql.createConnection({
host: 'localhost',
user: 'hscd',
database: 'hscd'
});
//
// Reviews
//
conn.query('DROP TABLE IF EXISTS reviews');
conn.query('CREATE TABLE reviews(name VARCHAR(100) NOT NULL, url VARCHAR(200) NOT NULL, food FLOAT, service FLOAT, value FLOAT, atmosphere FLOAT)');
for (var i = 0, count = data.length; i < count; ++i) {
var record = data[i];
conn.query('INSERT INTO reviews VALUES(?, ?, ?, ?, ?, ?)', [
record.name,
record.relativeUrl,
record.rating.food,
record.rating.service,
record.rating.value,
record.rating.atmosphere
]);
}
//
// Keywords
//
conn.query('DROP TABLE IF EXISTS keywords');
conn.query('CREATE TABLE keywords(name VARCHAR(50) NOT NULL, food FLOAT, service FLOAT, value FLOAT, atmosphere FLOAT)');
var keywords = {
'food': [1.0, 0.0, 0.0, 0.0],
'service': [0.0, 1.0, 0.0, 0.0],
'value': [0.0, 0.0, 1.0, 0.0],
'atmosphere': [0.0, 0.0, 0.0, 1.0]
};
for (var keyword in keywords) {
var record = keywords[keyword];
conn.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', [keyword].concat(record));
}
conn.end();

80
scrape/hscd.sql Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
#!/usr/bin/env nodejs
#!/usr/bin/env node
var cheerio = require('cheerio');
var request = require('request');