-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (57 loc) · 1.73 KB
/
index.js
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
const debug = require("debug")("gc:waldi");
const dedupe = require("./lib/dedupe");
const groundspeak = require("./lib/groundspeak");
const getLog = require("./lib/logInput");
const getTrackPoints = require("./lib/gpx");
const findCandidates = require("./lib/candidates");
const getGeocaches = require("./lib/geocaches");
const { canLogin } = require("./lib/groundspeak");
function getBounds(point) {
return [
point.lat + 0.001,
point.lon - 0.001,
point.lat - 0.001,
point.lon + 0.001
];
}
async function analyze(file) {
const points = getTrackPoints(file);
const candidates = findCandidates(points);
let seen = [];
for (const candidate of candidates) {
let box = getBounds(candidate);
let geocaches = await getGeocaches(box);
for (const geocache of geocaches) {
if (seen.includes(geocache.gc)) {
continue;
}
seen.push(geocache.gc);
if (dedupe.check(geocache.gc)) {
console.log("🙂 %s %s", geocache.gc, geocache.parsed.name);
} else {
if (!canLogin()) {
console.log(
"🤔 %s https://coord.info/%s",
geocache.parsed.name,
geocache.gc
);
continue;
}
const msg = await getLog(candidate, geocache);
if (msg == "EXIT") {
debug("Aborting processing");
return;
}
if (msg.length > 0) {
console.log("😀 %s %s", geocache.gc, geocache.parsed.name);
await groundspeak.postLog(geocache.gc, candidate.time, msg);
} else {
console.log("🤨 %s %s", geocache.gc, geocache.parsed.name);
}
dedupe.found(geocache.gc);
}
}
}
}
const filename = process.argv[2];
analyze(filename).catch(console.log);