Fixing interpreter name, creating database
This commit is contained in:
parent
2b3dd0b13a
commit
6a57a825f1
52
scrape/db.js
Executable file
52
scrape/db.js
Executable 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
80
scrape/hscd.sql
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env nodejs
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var cheerio = require('cheerio');
|
var cheerio = require('cheerio');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
Loading…
Reference in New Issue
Block a user