working sites importgit add *! WOOO! db-fill changed to fill-sites, new db script will be made for visits
This commit is contained in:
@ -3,7 +3,7 @@ var con = require('./db');
|
||||
con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
con.query("CREATE DATABASE unesco", function (err, res) {
|
||||
con.query("CREATE DATABASE unesco CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;", function (err, res) {
|
||||
if (err) throw err;
|
||||
console.log('"unesco" Database created.');
|
||||
});
|
||||
|
@ -1,35 +0,0 @@
|
||||
var con = require('./db');
|
||||
|
||||
con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
|
||||
con.query("USE unesco", function (err, res) {
|
||||
if (err) throw err;
|
||||
console.log('"unesco" Database selected.');
|
||||
});
|
||||
|
||||
sql = "INSERT INTO sites (category, in_danger, date_inscribed, unesco_url, latitude, longitude, description, site, unesco_unique) VALUES ?";
|
||||
val = [
|
||||
['Natural', true, '2007','https://whc.unesco.org/en/list/1133','49.0097222222', '22.3388888889', '<p><span>This transboundary property stretches over 12 countries. Since the end of the last Ice Age, European Beech spread from a few isolated refuge areas in the Alps, Carpathians</span><span>, Dinarides</span><span>, Mediterranean and Pyrenees over a short period of a few thousand years in a process that is still ongoing. The successful expansion across a whole continent is related to the tree’s </span><span>adaptability and tolerance of different climatic, geographical and physical conditions. </span></p>', 'Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe', '2152'],
|
||||
['Cultural', false, '2014','https://whc.unesco.org/en/list/1459','-18.2500000000', '-69.5916666667', '<p>This site is an extensive Inca communication, trade and defence network of roads covering 30,000 km. Constructed by the Incas over several centuries and partly based on pre-Inca infrastructure, this extraordinary network through one of the world’s most extreme geographical terrains linked the snow-capped peaks of the Andes – at an altitude of more than 6,000 m – to the coast, running through hot rainforests, fertile valleys and absolute deserts. It reached its maximum expansion in the 15th century, when it spread across the length a significance', 'Qhapaq Ñan, Andean Road System', '2003']
|
||||
];
|
||||
|
||||
con.query(sql, [val], function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("sites" + ": records inserted: " + res.affectedRows);
|
||||
});
|
||||
|
||||
sql = "INSERT INTO visits (date, img, site_id) VALUES ?";
|
||||
val = [
|
||||
['10-15-2019','https://seanland.ca', '1'],
|
||||
['10-17-2019','https://seanland.ca', '1']
|
||||
];
|
||||
|
||||
con.query(sql, [val], function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("visits" + ": records inserted: " + res.affectedRows);
|
||||
process.exit();
|
||||
});
|
||||
|
||||
});
|
77
database/fill-sites.js
Normal file
77
database/fill-sites.js
Normal file
@ -0,0 +1,77 @@
|
||||
var con = require('./db');
|
||||
var fs = require('fs');
|
||||
var parser = require('fast-xml-parser');
|
||||
|
||||
var string = fs.readFileSync(process.cwd() + '/data/unesco.xml', 'utf8').toString();
|
||||
|
||||
var val = parser.parse(string);
|
||||
var arr = [];
|
||||
|
||||
val.query.row.forEach(function(site){
|
||||
var s = [];
|
||||
s.push(site.category);
|
||||
s.push(site.danger != '' || false);
|
||||
s.push(site.date_inscribed);
|
||||
s.push(site.http_url);
|
||||
s.push(site.latitude);
|
||||
s.push(site.longitude);
|
||||
s.push(site.short_description);
|
||||
s.push(site.site);
|
||||
s.push(site.unique_number);
|
||||
// console.log(s);
|
||||
arr.push(s);
|
||||
});
|
||||
|
||||
console.log(arr);
|
||||
|
||||
con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
|
||||
sql = "INSERT INTO sites (category, in_danger, date_inscribed, unesco_url, latitude, longitude, description, site, unesco_unique) VALUES ?";
|
||||
|
||||
con.query(sql, [arr], function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("sites" + ": records inserted: " + res.affectedRows);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// fs.readFile(process.cwd() +'/data/unesco.xml', function(err, data) {
|
||||
// parser.parseString(data, function (err, result) {
|
||||
// result.query.row.forEach(function(site){
|
||||
// var danger = true;
|
||||
// var s = ['1','2','3','4','5','6','7','8','9'];
|
||||
// // var s = [site.category, site.danger, site.date_inscribed, site.http_url, site.latitude, site.longitude, site.short_description, site.site, site.unique_number];
|
||||
// con.query(sql, [[site.category, 1, site.date_inscribed, site.http_url, site.latitude, site.longitude, site.short_description, site.site, site.unique_number]], function(err, res){
|
||||
// if (err) throw err;
|
||||
// console.log("Site Imported: " + site.site);
|
||||
// });
|
||||
// // console.log(s);
|
||||
// });
|
||||
// console.log('Done');
|
||||
// });
|
||||
// });
|
||||
// console.log(val);
|
||||
|
||||
// con.query(sql, [val.query.row], function(err, res){
|
||||
// if (err) throw err;
|
||||
// console.log("sites" + ": records inserted: " + res.affectedRows);
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// sql = "INSERT INTO visits (date, img, site_id) VALUES ?";
|
||||
// val = [
|
||||
// ['10-15-2019','https://seanland.ca', '1'],
|
||||
// ['10-17-2019','https://seanland.ca', '1']
|
||||
// ];
|
||||
//
|
||||
// con.query(sql, [val], function(err, res){
|
||||
// if (err) throw err;
|
||||
// console.log("visits" + ": records inserted: " + res.affectedRows);
|
||||
// process.exit();
|
||||
// });
|
||||
|
||||
|
||||
// });
|
Reference in New Issue
Block a user