manual import rp3 working
This commit is contained in:
@@ -2712,6 +2712,84 @@ def handle_sendemail_invite_accept(email, name, teamname, managername,
|
||||
def add2(x, y,debug=False,**kwargs):
|
||||
return x + y
|
||||
|
||||
graphql_url = "https://rp3rowing-app.com/graphql"
|
||||
|
||||
@app.task
|
||||
def handle_rp3_async_workout(userid,rp3token,rp3id,startdatetime,debug=False,**kwargs):
|
||||
headers = {'Authorization': 'Bearer ' + rp3token }
|
||||
|
||||
get_download_link = """{
|
||||
download(workout_id: """ + str(rp3id) + """, type:csv){
|
||||
id
|
||||
status
|
||||
link
|
||||
}
|
||||
}"""
|
||||
|
||||
have_link = False
|
||||
download_url = ''
|
||||
counter = 0
|
||||
max_attempts = 20
|
||||
waittime = 3
|
||||
while not have_link:
|
||||
response = requests.post(
|
||||
url=graphql_url,
|
||||
headers=headers,
|
||||
json={'query': get_download_link}
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
have_link = True
|
||||
|
||||
workout_download_details = pd.json_normalize(response.json()['data']['download'])
|
||||
|
||||
if workout_download_details.iat[0,1] == 'ready':
|
||||
download_url = workout_download_details.iat[0,2]
|
||||
have_link = True
|
||||
|
||||
counter += 1
|
||||
|
||||
if counter>max_attempts:
|
||||
have_link = True
|
||||
|
||||
time.sleep(waittime)
|
||||
|
||||
filename = 'media/RP3Import_'+str(rp3id)+'.csv'
|
||||
res = requests.get(download_url,headers=headers)
|
||||
|
||||
if not startdatetime:
|
||||
startdatetime = str(timezone.now())
|
||||
|
||||
if res.status_code != 200:
|
||||
return 0
|
||||
|
||||
|
||||
with open(filename,'wb') as f:
|
||||
f.write(res.content)
|
||||
|
||||
uploadoptions = {
|
||||
'secret': UPLOAD_SERVICE_SECRET,
|
||||
'user': userid,
|
||||
'file': filename,
|
||||
'workouttype':'dynamic',
|
||||
'boattype':'1x',
|
||||
'rp3id':rp3id,
|
||||
'startdatetime':startdatetime,
|
||||
}
|
||||
|
||||
session = requests.session()
|
||||
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
session.headers.update(newHeaders)
|
||||
|
||||
response = session.post(UPLOAD_SERVICE_URL,json=uploadoptions)
|
||||
|
||||
if response.status_code != 200:
|
||||
return 0
|
||||
|
||||
workoutid = response.json()['id']
|
||||
|
||||
return workoutid
|
||||
|
||||
@app.task
|
||||
def handle_c2_async_workout(alldata,userid,c2token,c2id,debug=False,**kwargs):
|
||||
data = alldata[c2id]
|
||||
|
||||
Reference in New Issue
Block a user