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.
|
|
import Trimlog from './lib/client.mjs';
async function readStdin() { return new Promise((resolve) => { const allLines = []; let lingeringLine = ""; process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(chunk) { const lines = chunk.split("\n"); lines[0] = lingeringLine + lines[0]; lingeringLine = lines.pop(); allLines.push(...lines); }); process.stdin.on('end', function() { allLines.push(lingeringLine); resolve(allLines); }); }) }
function parseLine(line) { const split = line.split(" "); const split2 = split[0].split(/[:,.]/g); let seconds = parseInt(split2[0], 10) * 60; if (split2.length > 1) { seconds += parseInt(split2[1], 10); }
return ({ seconds, calories: parseInt(split[1]), }); }
async function main() { const [id] = process.argv.slice(2); if (!id) { return; }
const stuff = (await readStdin()) .filter(l => l) .map(parseLine) .map(l => ({...l, roundId: id}))
console.log(stuff);
const trimlog = new Trimlog({ username: process.env.TRIMLOG_USERNAME, password: process.env.TRIMLOG_PASSWORD, })
await trimlog.connect(); console.log("CONNECTED!")
trimlog.send("addRoundMeasurementBatch", { measurements: stuff, overwrite: true, });
process.on('SIGINT', function() { console.log("INTERRUPTED"); process.exit(0); });
process.on('SIGTERM', function() { console.log("TERMINATED"); process.exit(0); }); }
main();
|