Coder Social home page Coder Social logo

irwinwilliams / endomondo-api-handler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fabulator/endomondo-api-handler

0.0 0.0 0.0 1.76 MB

Unofficial handler for Endomondo API

License: Apache License 2.0

JavaScript 1.23% TypeScript 98.77%

endomondo-api-handler's Introduction

Endomondo API handler

npm version renovate-app Known Vulnerabilities codecov travis

This a handler for unofficial Endomondo API, which is used on their web app and mobile app. It allows you to read various of information and update them. This library is focused on searching, updating and creating workouts. Other endpoints you can find by sniffing your browser. Cooperation is welcome.

The library is based on my PHP library that do the similar.

The library is compiled for node 9.6. You are using this library on your own danger.

How it works

I use a library for handling REST API request - rest-api-handler. It is based on browser fetch feature so it needs polyfill.

Since this is not official API you need to use your login and password to log in.

How to use

Install npm library:

npm install endomondo-api-handler --save

Include fetch polyfill. I recommend cross-fetch:

import 'cross-fetch/polyfill';

There are two APIs. One is based on the web app and the second on the mobile app. You need Mobile API to create new workouts. Regular API will do everything else.

Authentize

If you need to create new workouts you need to authentize both to API and Mobile API.

const { Api, MobileApi } = require('endomondo-api-handler');

(async () => {
    const api = new Api();
    const mobileApi = new MobileApi();

    await Promise.all([
        api.login(login, password),
        mobileApi.login(login, password),
    ]);

    console.log(await api.get('rest/session'));
})();

Getting workout/s

To get single workout use getWorkout method:

const workout = await api.getWorkout(775131509);

Search for workouts:

const { DateTime } = require('luxon');

const { workouts } = await api.getWorkouts({
    after: DateTime.fromObject({
        year: 2018,
        month: 3,
        day: 1,
    }),
    limit: 2,
});
console.log(workouts);

Create a new workout

To create workout, use WorkoutFactory and MobileApi:

const { DateTime, Duration } = require('luxon');
const math = require('mathjs');
const { Point, Workout } = require('endomondo-api-handler');

const start = DateTime.fromObject({
    year: 2018,
    month: 3,
    day: 27,
    hour: 5,
    minute: 2,
});

const workout = Workout.get(
    Workout.SPORT.RUNNING,
    start,
    Duration.fromObject({ minutes: 3 }),
    math.unit(3, 'km'),
    [
        Point.get(start, 50.02957153, 14.51805568),
        Point.get(start.plus({ minutes: 1 }), 50.03057153, 14.52205568),
        Point.get(start.plus({ minutes: 2 }), 50.03357153, 14.53805568),
    ],
);

const workoutId = await mobileApi.createWorkout(workout);

Export your workouts to GPX

require('cross-fetch/polyfill');
const fs = require('fs');
const { Api } = require('endomondo-api-handler');

const api = new Api();

(async () => {
    await api.login(LOGIN, PASSWORD);

    await api.processWorkouts({}, async (workout) => {
        console.log(workout.toString());
        if (workout.hasGPSData()) {
            fs.writeFileSync(`tmp/${workout.getId()}.gpx`, await api.getWorkoutGpx(workout.getId()), 'utf8');
        }
    });
})();

Note - In old example gpx was generated by data from json response of Endomondo. I changed it to use getWorkoutGpx method which download gpx file directly from Endomondo and it's not processed by app.

Note 2 - When you are exporting tcx export of workout (by using method api.getWorkoutTcx) Endomondo sometimes creates workouts with duplicit IDs. To avoid this you can process tcx with simple replace:

tcx.replace(/<Id>([0-9]|-|T|:|Z)*<\/Id>/g, `<Id>${workout.getStart().toISO()}</Id>`)

endomondo-api-handler's People

Contributors

fabulator avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar vbouchet31 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.