-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapmyfitness_to_geojson.py
executable file
·41 lines (35 loc) · 1.5 KB
/
mapmyfitness_to_geojson.py
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
#!/usr/bin/python2.7
import json
import os.path
import re
import sys
import subprocess
full_workout_url = \
"http://api.mapmyfitness.com/3.1/workouts/get_workout_full?workout_id={0}"
def print_workouts_from_json_stream(instream):
output = json.load(instream)['result']['output']
if 'workouts' in output:
workouts = output['workouts']
elif 'workout' in output:
workouts = output['workout']['children']
else:
raise "Can't find workout list in results"
for workout in workouts:
# adjust date if format is weird
#
workout_date = re.sub(r'(\d+)/(\d+)/(\d+)',
r'\3-\1-\2', workout['workout_date'])
print workout_date + ',' + workout['distance']
if 'multi' in workout['workout_type_name'].lower() or 'multi' in \
workout['workout_description'].lower():
workout_id = workout['workout_id']
# print 'need to get more info based on ' +
# workout['workout_type_name'] + ', ' +
# workout['workout_description'] + ', ' + workout['workout_id']
process = subprocess.Popen([os.path.dirname(__file__) +
"/mapmyfitness.py",
full_workout_url.format(workout_id)],
stdout=subprocess.PIPE)
print_workouts_from_json_stream(process.stdout)
# print process.stdout.read()
print_workouts_from_json_stream(sys.stdin)