-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
110 lines (102 loc) · 2.74 KB
/
Copy pathindex.js
File metadata and controls
110 lines (102 loc) · 2.74 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var googleMapsClient = require('@google/maps').createClient({
key: 'AIzaSyD2U7TiCUANSUFYhC27-Duno0kr0_5kzF0'
});
const MongoClient = require('mongodb').MongoClient;
let db = null;
function connectDB(callback) {
MongoClient.connect("mongodb://35.154.122.180", function(err, client){
if(err) {
console.log("Error connecting to database", err);
return callback(false);
}
callback(client);
});
}
function insertData(collection, data) {
db.collection(collection).insert(data);
console.log("Inserting data");
}
function storeGoogleData(school, school_details) {
/*
console.log("AAA", Object.keys(school_details));
let c = 0;
for(let i in school_details) {
console.log(i, school_details[i]);
console.log("---------------------");
c += 1;
}
*/
insertData('preschool', {
name : school_details.name,
courses : school_details.courses,
highlights: school_details.highlights,
facilities: school_details.facilities,
reviews : school_details.reviews,
qna : school_details.qna, // q&a
gallery: {
google_maps: school_details.photos
},
logo: school_details.icon,
scholarship: scholarship.scholarship,
contacts: {
address: school_details.address_components,
adr_address: school_details.adr_address,
formatted_address: school_details.formatted_address,
website: school_details.website,
phone: school_details.international_phone_number,
formatted_phone_number: school_details.formatted_phone_number,
geometry: school_details.geometry,
vicinity: school_details.vicinity
},
fees: school_details.fees,
admission_time: school_details.admission_time,
admission_eligibility : school_details.admission_eligibility,
data_from : 'google_maps',
other: {
place_id: school_details.place_id,
rating: school_details.rating,
url: school_details.url,
reference: school_details.reference
}
});
}
function gatherData(search_query) {
googleMapsClient.places({ query: search_query }, function(err, response){
if (!err) {
// console.log(response.json.results);
let list = response.json.results;
for(let i in list) {
let school = list[i];
// console.log(school);
googleMapsClient.place({ placeid: school.place_id }, function(err, response){
if(err) {
console.log("Err", err);
return;
}
// console.log("Details", response.json.result);
storeGoogleData(school, response.json.result);
});
break;
}
} else {
console.log("ERROR: ", err);
}
});
}
function init(){
connectDB((conn) => {
if(!conn) {
console.log("DB Connection unsuccessfull");
process.exit();
}
db = conn.db("education");
gatherData("preschool in hyderabad");
});
}
module.exports = {
connectDB: connectDB
}
if (!module.parent) {
init();
// console.log("BBB", module.parent);
}