Private
Public Access
1
0

garmin work

This commit is contained in:
Sander Roosendaal
2021-05-05 16:31:18 +02:00
parent bf1bde95ad
commit 5fc274e834
2 changed files with 95 additions and 5 deletions

83
garminscript.py Normal file
View File

@@ -0,0 +1,83 @@
from requests_oauthlib import OAuth1Session, OAuth1
import hmac
import hashlib
import requests
from urllib.parse import quote_plus as rawurlencode
import logging
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': 'Step', 'stepOrder': 0,
'repeatType': 'Step',
'repeatValue': 1,
'intensity': 'Active',
'description': '0',
'durationType': 'TIME',
'durationValue': 1800,
'durationValueType': '',
'targetType': 'Power',
'targetValue': 1226,
'targetValueLow': 0, 'targetValueHigh': (0,)
}
]
}
payload = {}
oauth_consumer_key = b'ca29ba5e-6868-4468-987d-4ee60a1f04bf'
oauth_consumer_secret = b'SKRqjML9mOBV7BcPpN7LsbuDNDtvLOvRiyo'
oauth_token = b'79454eab-bf82-4329-9de2-82a6bd911498'
oauth_token_secret = b'DihdHJ2ThEdbsyoStpPTEmYh5F52L697HhD'
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,payload,auth=authheaders)
# build base_string
base_string1 = b'POST&https%3A%2F%2Fapis.garmin.com%2Ftraining-api%2Fworkout%2F&description%3DUploaded%2520from%2520Rowsandall.com%26estimatedDistanceInMeters%3D6936%26estimatedDurationInSecs%3D1800%26oauth_consumer_key%3Dca29ba5e-6868-4468-987d-4ee60a1f04bf%26oauth_nonce%3D163208869057942765101620205416%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1620205416%26oauth_token%3D79454eab-bf82-4329-9de2-82a6bd911498%26oauth_version%3D1.0%26sport%3DGENERIC%26steps%3Ddescription%26steps%3DdurationType%26steps%3DdurationValue%26steps%3DdurationValueType%26steps%3Dintensity%26steps%3DrepeatType%26steps%3DrepeatValue%26steps%3DstepOrder%26steps%3DtargetType%26steps%3DtargetValue%26steps%3DtargetValueHigh%26steps%3DtargetValueLow%26steps%3Dtype%26workoutName%3D30min%2520at%2520threshold%26workoutProvider%3DRowsandall.com%26workoutSourceId%3DRowsandall.com'
base_stringa = b'POST&https%3A%2F%2Fapis.garmin.com%2Ftraining-api%2Fworkout%2F&oauth_consumer_key%3Dca29ba5e-6868-4468-987d-4ee60a1f04bf%26oauth_nonce%3D90559685229655402871620208938%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1620208938%26oauth_token%3D79454eab-bf82-4329-9de2-82a6bd911498%26oauth_version%3D1.0'
base_string2 = b'POST&https%3A%2F%2Fapis.garmin.com%2Ftraining-api%2Fworkout%2F&oauth_consumer_key%3Dca29ba5e-6868-4468-987d-4ee60a1f04bf%26oauth_nonce%3DIyk9Ambokd2%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1620138340%26oauth_token%3D673806b7-aa7b-4064-8290-2dd1b0236ae6%26oauth_version%3D1.0'
base_string3 = b'POST&https%3A%2F%2Fapis.garmin.com%2Ftraining-api%2Fworkout&oauth_consumer_key%3Dca29ba5e-6868-4468-987d-4ee60a1f04bf%26oauth_nonce%3D90559685229655402871620208938%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1620208938%26oauth_token%3D79454eab-bf82-4329-9de2-82a6bd911498%26oauth_version%3D1.0'
auth = b'&'.join([oauth_consumer_secret,oauth_token_secret])
signingKey = bytes(rawurlencode(oauth_consumer_secret) + "&" + rawurlencode(oauth_token_secret),'utf-8')
print(auth)
print(signingKey)
print(base_string3)
sig = hmac.new(signingKey, base_string3, hashlib.sha1)
print(response.status_code)
print(response.text)
print(sig.hexdigest().encode())

View File

@@ -35,11 +35,11 @@ from pytz import timezone as tz, utc
#http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.
#logging.basicConfig()
#logging.getLogger().setLevel(logging.DEBUG)
#requests_log = logging.getLogger("requests.packages.urllib3")
#requests_log.setLevel(logging.DEBUG)
#requests_log.propagate = True
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
from rowers.tasks import handle_get_garmin_file
@@ -305,6 +305,11 @@ def ps_to_garmin(ps,r):
payload['steps'] = lijst
url = 'https://apis.garmin.com/training-api/workout/'
print(payload)
print(oauth_data['client_id'])
print(oauth_data['client_secret'])
print(r.garmintoken)
print(r.garminrefreshtoken)
garmin = OAuth1Session(oauth_data['client_id'],
client_secret=oauth_data['client_secret'],
@@ -314,6 +319,8 @@ def ps_to_garmin(ps,r):
encoding='base64'
)
print(garmin.headers)
response = garmin.post(url,data=payload)
#POST /training-api/workout?undefined HTTP/1.1