20
20
from mind_monitor_data_download_db_insert import mm_data_insert
21
21
from weather import get_weather
22
22
from send_email import send_email
23
+ from oura_data_download import dwnld_insert_oura_data
23
24
import psutil
24
25
import urllib .request , urllib .error , urllib .parse
25
26
from database_ini_parser import config
31
32
from Crypto .Cipher import AES
32
33
import base64
33
34
from requests_oauthlib import OAuth2Session
34
-
35
+
35
36
#----Crypto Variables----
36
37
# salt size in bytes
37
38
SALT_SIZE = 16
@@ -73,6 +74,10 @@ def encrypt(plaintext, password):
73
74
OURA_CLIENT_SECRET = str (oura_params .get ("oura_client_secret" ))
74
75
OURA_AUTH_URL = str (oura_params .get ("oura_auth_url" ))
75
76
OURA_TOKEN_URL = str (oura_params .get ("oura_token_url" ))
77
+ if OURA_CLIENT_ID == "" :
78
+ oura_enabled = False
79
+ else :
80
+ oura_enabled = True
76
81
77
82
anticaptcha_params = config (filename = "encrypted_settings.ini" , section = "anticaptcha" ,encr_pass = encr_pass )
78
83
anticaptcha_api_key = str (anticaptcha_params .get ("api_key" ))
@@ -127,6 +132,7 @@ def index():
127
132
gc_fit_activ_progress = None
128
133
gc_tcx_activ_progress = None
129
134
gc_fit_well_progress = None
135
+ oura_well_progress = None
130
136
gc_json_well_progress = None
131
137
gc_json_dailysum_progress = None
132
138
progress_error = False
@@ -150,7 +156,7 @@ def index():
150
156
elif gc_login_radio == 'getGCcredfromCSV' :
151
157
gc_username = str (request .form .get ('gcUN' ))
152
158
gc_password = str (request .form .get ('gcPW' ))
153
-
159
+
154
160
#----Destination DB variables-----
155
161
db_name = str (str2md5 (gc_username )) + '_Athlete_Data_DB'
156
162
@@ -165,7 +171,7 @@ def index():
165
171
connection = check_db_server_connectivity (gc_username ,db_host ,superuser_un ,superuser_pw )
166
172
if connection != 'SUCCESS' :
167
173
flash (' Could cot connect to the DB Host.The host returned an error: ' + connection ,'danger' )
168
- return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
174
+ return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
169
175
else :
170
176
#If user does not wish to download to his db, credentials to be retrieved from .ini.
171
177
params = config (filename = "encrypted_settings.ini" , section = "postgresql" ,encr_pass = encr_pass )
@@ -178,13 +184,13 @@ def index():
178
184
host_record_exists = check_host_record_exists (gc_username ,db_name ,db_host ,encr_pass )
179
185
if host_record_exists == True :
180
186
flash (' You can only download to one db host. Please correct the db_hostname and try again' ,'warning' )
181
- return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
187
+ return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
182
188
183
189
#----Check if the provided GC credentials are valid-----
184
190
gc_cred_valid = gc .check_gc_creds (gc_username ,gc_password )
185
191
if gc_cred_valid == False :
186
192
flash (' The Garmin Connect login credentials are not valid. Please try again' ,'warning' )
187
- return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
193
+ return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
188
194
189
195
190
196
#----- Set Auto_Synch variables--------
@@ -275,7 +281,7 @@ def index():
275
281
else :
276
282
return redirect (url_for ('oura_auth_request' ))
277
283
278
- # CLEANUP BEFORE DOWNLOAD -----------------
284
+ # CLEANUP BEFORE DOWNLOAD -----------------
279
285
280
286
#----Delete Files and DB Data variables----
281
287
try :
@@ -361,7 +367,7 @@ def index():
361
367
time .sleep (1 )
362
368
with ProgressStdoutRedirection (gc_username ):
363
369
print (del_progress )
364
- return render_template ("index.html" ,del_progress = del_progress ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
370
+ return render_template ("index.html" ,del_progress = del_progress ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
365
371
except :
366
372
del_progress = 'Error deleting data'
367
373
progress_error = True
@@ -370,9 +376,9 @@ def index():
370
376
time .sleep (1 )
371
377
with ErrorStdoutRedirection (gc_username ):
372
378
print ((str (datetime .datetime .now ()) + ' ' + del_progress ))
373
- return render_template ("index.html" ,del_progress = del_progress ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
379
+ return render_template ("index.html" ,del_progress = del_progress ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
374
380
375
-
381
+
376
382
if gc_username is None and gc_password is None and mfp_username is None and mfp_password is None :
377
383
progress_error = True
378
384
continue_btn = 'none'
@@ -402,7 +408,7 @@ def index():
402
408
print ((str (datetime .datetime .now ()) + ' ' + str (e )))
403
409
#PG:If start date not provided render index and flash warning
404
410
flash (' Please provide a valid start date and try again!' ,'danger' )
405
- return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
411
+ return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
406
412
407
413
# DATA DOWNLOAD --------------------------------------
408
414
@@ -427,7 +433,7 @@ def index():
427
433
with ErrorStdoutRedirection (gc_username ):
428
434
print ((str (datetime .datetime .now ()) + ' ' + gc_login_progress ))
429
435
flash (' There was a problem logging in to Garmin Connect. Please try again later' ,'warning' )
430
- return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
436
+ return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
431
437
432
438
#---------------------------------- Activity ---------------------------------------
433
439
@@ -482,10 +488,6 @@ def index():
482
488
with ErrorStdoutRedirection (gc_username ):
483
489
print ((str (datetime .datetime .now ()) + ' ' + gc_fit_well_progress ))
484
490
485
- #TODO:
486
- #PG:Call to execute "Parse and insert Oura wellness data" script
487
- #TODO
488
-
489
491
#PG:Call to execute "Parse and insert JSON wellness data" script
490
492
try :
491
493
gc_json_well_progress = 'GC JSON wellness download started'
@@ -535,6 +537,31 @@ def index():
535
537
with ErrorStdoutRedirection (gc_username ):
536
538
print ((str (datetime .datetime .now ()) + ' ' + gc_json_dailysum_progress ))
537
539
540
+ #PG:Call to execute "Parse and insert Oura wellness data" script
541
+ if request .form .get ('ouraCheckbox' ) is not None :
542
+ try :
543
+ oura_well_progress = 'Oura wellness download started'
544
+ with StdoutRedirection (gc_username ):
545
+ print (oura_well_progress )
546
+ time .sleep (1 )
547
+ dwnld_insert_oura_data (gc_username ,db_host ,db_name ,superuser_un ,superuser_pw ,oura_refresh_token ,start_date ,end_date ,save_pwd ,encr_pass )
548
+ oura_well_progress = 'Oura wellness data downloaded successfully'
549
+ with StdoutRedirection (gc_username ):
550
+ print (oura_well_progress )
551
+ time .sleep (1 )
552
+ with ProgressStdoutRedirection (gc_username ):
553
+ print (oura_well_progress )
554
+ except Exception as e :
555
+ with ErrorStdoutRedirection (gc_username ):
556
+ print ((str (datetime .datetime .now ()) + ' ' + str (e )))
557
+ oura_well_progress = 'Error downloading Oura wellness data'
558
+ progress_error = True
559
+ with StdoutRedirection (gc_username ):
560
+ print (oura_well_progress )
561
+ time .sleep (1 )
562
+ with ErrorStdoutRedirection (gc_username ):
563
+ print ((str (datetime .datetime .now ()) + ' ' + oura_well_progress ))
564
+
538
565
#----------------- Nutrition MFP ---------------------------
539
566
#PG:Call to execute "parse and insert MFP data" script
540
567
if mfp_username is not None :
@@ -678,9 +705,9 @@ def index():
678
705
print (('--------------- ' + str (datetime .datetime .now ()) + ' User ' + gc_username + ' Finished Data Download ' + error_log_entry + ' -------------' ))
679
706
680
707
return render_template ("index.html" ,del_progress = del_progress ,mfp_progress = mfp_progress ,diasend_progress = diasend_progress ,glimp_progress = glimp_progress , mm_progress = mm_progress , gc_login_progress = gc_login_progress ,
681
- gc_fit_activ_progress = gc_fit_activ_progress ,gc_tcx_activ_progress = gc_tcx_activ_progress ,
682
- gc_fit_well_progress = gc_fit_well_progress , gc_json_well_progress = gc_json_well_progress ,
683
- gc_json_dailysum_progress = gc_json_dailysum_progress , progress_error = progress_error , continue_btn = continue_btn , admin_email = admin_email , integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
708
+ gc_fit_activ_progress = gc_fit_activ_progress ,gc_tcx_activ_progress = gc_tcx_activ_progress , gc_fit_well_progress = gc_fit_well_progress , gc_json_well_progress = gc_json_well_progress ,
709
+ gc_json_dailysum_progress = gc_json_dailysum_progress , oura_well_progress = oura_well_progress , progress_error = progress_error , continue_btn = continue_btn , admin_email = admin_email ,
710
+ integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
684
711
685
712
except Exception as e :
686
713
with ErrorStdoutRedirection (gc_username ):
@@ -693,7 +720,7 @@ def index():
693
720
694
721
else : # Request method is GET
695
722
continue_btn = request .args .get ('continue_btn' )
696
- return render_template ("index.html" ,continue_btn = continue_btn ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
723
+ return render_template ("index.html" ,continue_btn = continue_btn ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
697
724
698
725
@app .route ("/datamodel_preview" )
699
726
def datamodel_preview ():
@@ -783,7 +810,7 @@ def db_info():
783
810
db_username = None
784
811
password_info = None
785
812
flash (' The DB name, DB role and DB permissions are generated based on your Garmin Connect username. Please fill in your GC credentials and try again. This information is not recorded anywhere until you proceed with the download and the AutoSynch option is enabled.' ,'warning' )
786
- return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled )
813
+ return render_template ("index.html" ,admin_email = admin_email ,integrated_with_dropbox = integrated_with_dropbox ,diasend_enabled = diasend_enabled , oura_enabled = oura_enabled )
787
814
788
815
@app .route ("/dropbox_auth_request" )
789
816
def dropbox_auth_request ():
0 commit comments