You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
70 lines
1.8 KiB
import gc from 'garmin-connect';
|
|
import Trimlog from './lib/client.mjs';
|
|
import fs from "fs/promises";
|
|
import { today } from './lib/tcx.mjs';
|
|
|
|
async function main() {
|
|
const garmin = new gc.GarminConnect({
|
|
username: process.env.GARMIN_USERNAME,
|
|
password: process.env.GARMIN_PASSWORD,
|
|
});
|
|
const trimlog = new Trimlog({
|
|
username: process.env.TRIMLOG_USERNAME,
|
|
password: process.env.TRIMLOG_PASSWORD,
|
|
})
|
|
|
|
await trimlog.submit({});
|
|
await garmin.login();
|
|
|
|
console.log("CONNECTED!");
|
|
|
|
const blackList = {};
|
|
|
|
setInterval(async() => {
|
|
|
|
const activities = await garmin.getActivities();
|
|
const todayDate = today();
|
|
for (const act of activities) {
|
|
const id = Math.round(act.activityId).toFixed(0);
|
|
|
|
if (blackList[id]) {
|
|
continue;
|
|
}
|
|
|
|
if (!["walking", "cycling"].includes(act.activityType?.typeKey)) {
|
|
console.error("Skipping", act.activityId, `(${act.activityType?.typeKey} activity not supported)`);
|
|
blackList[id] = true;
|
|
continue;
|
|
}
|
|
if (!act.startTimeLocal.startsWith(todayDate)) {
|
|
console.error("Skipping", act.activityId, "(not today)");
|
|
blackList[id] = true;
|
|
continue;
|
|
}
|
|
|
|
console.log("Going ahead with", act.activityId, act.activityType.typeKey)
|
|
|
|
await garmin.downloadOriginalActivityData(act, "/tmp/", "tcx")
|
|
const input = (await fs.readFile(`/tmp/${act.activityId}.tcx`)).toString("base64")
|
|
|
|
await trimlog.submit({addUpload: {
|
|
name: `${act.activityId}.tcx`,
|
|
base64: input,
|
|
}});
|
|
|
|
blackList[id] = true;
|
|
}
|
|
}, 300000);
|
|
|
|
process.on('SIGINT', function() {
|
|
console.log("INTERRUPTED");
|
|
process.exit(0);
|
|
});
|
|
|
|
process.on('SIGTERM', function() {
|
|
console.log("TERMINATED");
|
|
process.exit(0);
|
|
});
|
|
}
|
|
|
|
main();
|