JasonSanford / mapmyfitness-python

A Python wrapper for the MapMyFitness API
MIT License
9 stars 6 forks source link

mapmyfitness-python

Build Status Coverage Status

A Python wrapper for the MapMyFitness API

Status

This is a work in progress. Current endpoints implemented are:

Contributing

See Contributing

Installation

Install via pip:

pip install mapmyfitness

or from local sources:

python setup.py install

Dependencies

Usage

Instantiate an instance of MapMyFitness with your API key and an access token representing a user:

from mapmyfitness import MapMyFitness
mmf = MapMyFitness(api_key='not-so-secret', access_token='super-secret')

Optionally pass True for cache_finds. This will cache instances of objects fetched through the find method. This is helpful for objects that aren't likely to change, like Activity Types.

from mapmyfitness import MapMyFitness
mmf = MapMyFitness(api_key='not-so-secret', access_token='super-secret', cache_finds=True)

Routes

Implements behaviors: find, search, create, delete, update

Search Parameters

* One of user, users or close_to_location parameters must be passed.

Route Object Properties

Route Object Methods

Examples

Search for routes created by a user:

routes_paginator = mmf.route.search(user=9118466)

Search for 10k routes near a specific location:

routes_paginator = mmf.route.search(close_to_location=[35.555, -80.934], minimum_distance=9000, maximum_distance=11000)

Workouts

Implements behaviors: find, search, create, delete, update

Search Parameters

Workout Object Properties

Examples

Find all workouts for a user in the year 2013

start_datetime = datetime.datetime(2013, 1, 1)
end_datetime = datetime.datetime(2014, 1, 1)

workouts_paginator = mmf.workout.search(user=9118466, per_page=40, started_after=start_datetime, started_before=end_datetime)

for page_num in workouts_paginator.page_range:
    the_page = workouts_paginator.page(page_num)
    for workout in the_page:
        print(workout.start_datetime)

Users

Implements behaviors: find, search

Search Parameters

User Object Properties

User Object Methods

Activity Types

Implements behaviors: find

Activity Type Object Properties

Behaviors

find

Find a single object by its unique id. Returns a object or raises mapmyfitness.exceptions.NotFoundException if no object is found.

Example

route = mmf.route.find(348949363)
print(route.name)  # '4 Mile Lunch Run'

search

Search for objects. Returns a Paginator object to easily page through large result sets.

See this gist for implementation details.

Paginator Properties

Paginator Methods

Example Usage

start_datetime = datetime.datetime(2014, 1, 1)
end_datetime = datetime.datetime(2015, 1, 1)

workouts_paginator = mmf.workout.search(user=9118466, per_page=40, started_after=start_datetime, started_before=end_datetime)

page_count = workouts_paginator.num_pages  # 2
page_range = workouts_paginator.page_range # [1, 2]
total_count = workouts_paginator.count # 58

for page_num in page_range:
    the_page = workouts_paginator.page(page_num)
    print(the_page)  # <Page 1 of 2>
    for workout in the_page:
        print(workout.start_datetime)  # 2014-01-02 02:59:53+00:00

create

Create an object.

delete

Delete an object.

Example

mmf.route.delete(348949363)

Returns None on success or raises mapmyfitness.exceptions.NotFoundException if the object doesn't exist.

update

Update an object.