Private
Public Access
1
0
Files
rowsandall/garminscript.py
2021-05-16 05:21:38 +02:00

99 lines
2.7 KiB
Python

from requests_oauthlib import OAuth1Session, OAuth1
import hmac
import hashlib
import arrow
import datetime
import json
import requests
from urllib.parse import quote_plus as rawurlencode
import logging
import uuid
#logging.basicConfig()
#logging.getLogger().setLevel(logging.DEBUG)
#requests_log = logging.getLogger("requests.packages.urllib3")
#requests_log.setLevel(logging.DEBUG)
#requests_log.propagate = True
payload = {
'workoutName': '30min at threshold',
'sport': 'GENERIC',
'description': 'Uploaded from Rowsandall.com',
'estimatedDurationInSecs': 1800,
'estimatedDistanceInMeters': 6936,
'workoutProvider': 'Rowsandall.com',
'workoutSourceId': 'Rowsandall.com',
'steps': [
{
'type': 'WorkoutStep', 'stepOrder': 0,
#'repeatType': 'Step',
'repeatValue': 1,
'intensity': 'ACTIVE',
'description': '0',
'durationType': 'TIME',
'durationValue': 1800,
'durationValueType': 'METER',
'targetType': 'POWER',
'targetValue': 1226,
'targetValueLow': None,
'targetValueHigh': None,
}
]
}
payload = {
"workoutName": "Test",
"description": "Test",
"sport": "CYCLING",
"steps": [
{
"type": "WorkoutStep",
"stepOrder": 1,
"intensity": "INTERVAL",
"description": "Free Ride",
"durationType": "TIME",
"durationValue": 300,
"durationValueType": None,
"targetType": "POWER",
"targetValue": None,
"targetValueLow": 0,
"targetValueHigh": 0.7,
"targetValueType": "PERCENT",
"exerciseCategory": None
}]}
print(json.dumps(payload))
oauth_consumer_key = 'ca29ba5e-6868-4468-987d-4ee60a1f04bf'
oauth_consumer_secret = 'SKRqjML9mOBV7BcPpN7LsbuDNDtvLOvRiyo'
oauth_token = '79454eab-bf82-4329-9de2-82a6bd911498'
oauth_token_secret = 'DihdHJ2ThEdbsyoStpPTEmYh5F52L697HhD'
oauth_token='673806b7-aa7b-4064-8290-2dd1b0236ae6'
oauth_token_secret='Ci0m4nKLs4Cfpnw856s2BKQRlDJa6nxdmX5'
authheaders = OAuth1(client_key=oauth_consumer_key,
client_secret=oauth_consumer_secret,
resource_owner_key=oauth_token,
resource_owner_secret=oauth_token_secret,
signature_method='HMAC-SHA1',
#encoding='base64'
)
url = 'https://apis.garmin.com/training-api/workout'
response = requests.post(url,auth=authheaders,json=payload)
#therequest = requests.prepare_request()
# build base_string
print(response.status_code)
print(response.text)