creating auth url, not implemented callback yet
This commit is contained in:
@@ -5,6 +5,7 @@ from .sporttracks import SportTracksIntegration
|
||||
from .rp3 import RP3Integration
|
||||
from .trainingpeaks import TPIntegration
|
||||
from .polar import PolarIntegration
|
||||
from .intervals import IntervalsIntegration
|
||||
|
||||
importsources = {
|
||||
'c2': C2Integration,
|
||||
@@ -15,5 +16,6 @@ importsources = {
|
||||
'tp':TPIntegration,
|
||||
'rp3':RP3Integration,
|
||||
'polar': PolarIntegration,
|
||||
'intervals': IntervalsIntegration,
|
||||
}
|
||||
|
||||
|
||||
92
rowers/integrations/intervals.py
Normal file
92
rowers/integrations/intervals.py
Normal file
@@ -0,0 +1,92 @@
|
||||
from .integrations import SyncIntegration, NoTokenError, create_or_update_syncrecord, get_known_ids
|
||||
from rowers.models import Rower, User, Workout, TombStone
|
||||
from rowingdata import rowingdata
|
||||
|
||||
from rowers import mytypes
|
||||
|
||||
from rowers.rower_rules import is_workout_user, ispromember
|
||||
from rowers.utils import myqueue, dologging, custom_exception_handler
|
||||
|
||||
import urllib
|
||||
import gzip
|
||||
import requests
|
||||
import arrow
|
||||
import datetime
|
||||
import os
|
||||
from uuid import uuid4
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
INTERVALS_CLIENT_ID, INTERVALS_REDIRECT_URI, INTERVALS_CLIENT_SECRET, SITE_URL
|
||||
)
|
||||
|
||||
import django_rq
|
||||
queue = django_rq.get_queue('default', default_timeout=3600)
|
||||
queuelow = django_rq.get_queue('low', default_timeout=3600)
|
||||
queuehigh = django_rq.get_queue('high', default_timeout=3600)
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
|
||||
intervals_authorize_url = 'https://intervals.icu/oauth/authorize?'
|
||||
intervals_token_url = 'https://intervals.icu/oauth/token'
|
||||
|
||||
class IntervalsIntegration(SyncIntegration):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(IntervalsIntegration, self).__init__(*args, **kwargs)
|
||||
self.oauth_data = {
|
||||
'client_id': INTERVALS_CLIENT_ID,
|
||||
'client_secret': INTERVALS_CLIENT_SECRET,
|
||||
'redirect_uri': INTERVALS_REDIRECT_URI,
|
||||
'authorization_uri': intervals_authorize_url,
|
||||
'content_type': 'application/json',
|
||||
'tokenname': 'intervals_token',
|
||||
'expirydatename': 'intervals_exp',
|
||||
'refreshtokenname': 'intervals_r',
|
||||
'bearer_auth': True,
|
||||
'base_uri': 'https://intervals.icu/api/v1/',
|
||||
'grant_type': 'refresh_token',
|
||||
'headers': headers,
|
||||
'scope': 'ACTIVITY:WRITE'
|
||||
}
|
||||
|
||||
def get_token(self, code, *args, **kwargs):
|
||||
return super(IntervalsIntegration, self).get_token(code, *args, **kwargs)
|
||||
|
||||
def get_name(self):
|
||||
return 'Intervals'
|
||||
|
||||
def get_shortname(self):
|
||||
return 'intervals'
|
||||
|
||||
def open(self, *args, **kwargs):
|
||||
dologging('intervals.icu.log', "Getting token for user {id}".format(id=self.rower.id))
|
||||
token = super(IntervalsIntegration).open(*args, **kwargs)
|
||||
return token
|
||||
|
||||
def createworkoutdata(self, w, *args, **kwargs) -> str:
|
||||
return NotImplemented
|
||||
|
||||
def workout_export(self, workout, *args, **kwargs) -> str:
|
||||
return NotImplemented
|
||||
|
||||
def get_workouts(workout, *args, **kwargs) -> int:
|
||||
return NotImplemented
|
||||
|
||||
def get_workout(self, id, *args, **kwargs) -> int:
|
||||
return NotImplemented
|
||||
|
||||
def get_workout_list(self, *args, **kwargs) -> list:
|
||||
return NotImplemented
|
||||
|
||||
def make_authorization_url(self, *args, **kwargs):
|
||||
return super(IntervalsIntegration, self).make_authorization_url(*args, **kwargs)
|
||||
|
||||
def token_refresh(self, *args, **kwargs):
|
||||
return super(IntervalsIntegration, self).token_refresh(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
@@ -1240,6 +1240,11 @@ class Rower(models.Model):
|
||||
strava_auto_import = models.BooleanField(default=False)
|
||||
strava_auto_delete = models.BooleanField(default=False)
|
||||
|
||||
intervals_token = models.CharField(
|
||||
default='', max_length=200, blank=True, null=True)
|
||||
intervals_exp = models.DateTimeField(blank=True, null=True)
|
||||
intervals_r = models.CharField(default='', max_length=200, blank=True, null=True)
|
||||
|
||||
privacychoices = (
|
||||
('visible', 'Visible'),
|
||||
('hidden', 'Hidden'),
|
||||
|
||||
@@ -296,6 +296,21 @@ C2_CLIENT_SECRET = CFG['c2_client_secret']
|
||||
C2_REDIRECT_URI = CFG['c2_callback']
|
||||
# C2_REDIRECT_URI = "http://localhost:8000/call_back"
|
||||
|
||||
# Intervals.icu
|
||||
try:
|
||||
INTERVALS_CLIENT_ID = CFG['intervals_client_id']
|
||||
except KeyError:
|
||||
INTERVALS_CLIENT_ID = '0'
|
||||
|
||||
try:
|
||||
INTERVALS_CLIENT_SECRET = CFG['intervals_client_secret']
|
||||
except KeyError:
|
||||
INTERVALS_CLIENT_SECRET = 'aa'
|
||||
try:
|
||||
INTERVALS_REDIRECT_URI = CFG['intervals_callback']
|
||||
except KeyError:
|
||||
INTERVALS_REDIRECT_URI = 'http://localhost:8000/intervals_icu_callback'
|
||||
|
||||
# Strava
|
||||
|
||||
STRAVA_CLIENT_ID = CFG['strava_client_id']
|
||||
|
||||
Reference in New Issue
Block a user