-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostboxstore.js
More file actions
60 lines (56 loc) · 1.98 KB
/
postboxstore.js
File metadata and controls
60 lines (56 loc) · 1.98 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
// Init Firebase
var firebase = require("firebase/app");
var postboxes = require('./postboxes.json');
require("firebase/firestore");
var config = {
"apiKey": "AIzaSyAl4uzvsZ1m05Dw0U19vkcq6b1IqYHJOdA",
"databaseURL": "https://the-postbox-game.firebaseio.com",
"storageBucket": "the-postbox-game.appspot.com",
"authDomain": "the-postbox-game.firebaseapp.com",
"messagingSenderId": "176793005702",
"projectId": "the-postbox-game"
};
firebase.initializeApp(config);
const _cliProgress = require('cli-progress');
// create a new progress bar instance and use shades_classic theme
const bar1 = new _cliProgress.Bar({}, _cliProgress.Presets.shades_classic);
// Init GeoFireX
var geofirex = require('geofirex');
const geo = geofirex.init(firebase);
const postbox_collection = geo.collection('postboxes');
const total = postboxes.elements.length;
bar1.start(total, 0);
let progress = 0;
postboxes.elements.forEach(async (postbox) => {
if(postbox.type == 'node'){
if(typeof postbox.id != 'undefined'){
const point = geo.point(postbox.lat, postbox.lon);
let postbox_document = {
overpass_id:postbox.id,
position: point.data
}
const tags = Object.keys(postbox.tags);
for (let index = 0; index < tags.length; index++) {
const tag = tags[index];
const value = postbox.tags[tag];
switch(tag){
case 'ref':
postbox_document.reference = value;
break;
case 'royal_cypher':
postbox_document.monarch = value;
break;
}
}
await postbox_collection.add(postbox_document);
}
}
progress++;
bar1.update(progress);
});
/*
const cities = geo.collection('postboxes');
// lat, long
const point = geo.point(40, -119);
cities.add({ name: 'Phoenix', position: point.data });
*/