5
5
6
6
import altair as alt
7
7
import numpy as np
8
+ import os
9
+ import json
8
10
import pandas as pd
9
-
11
+ import penn_chime . spreadsheet as sp
10
12
from .constants import (
11
13
CHANGE_DATE ,
12
14
DOCS_URL ,
@@ -172,6 +174,8 @@ def display_sidebar(st, d: Parameters) -> Parameters:
172
174
# it's kindof like ember or angular if you are familiar with those
173
175
174
176
st_obj = st .sidebar
177
+ # used_widget_key = st.get_last_used_widget_key ( )
178
+
175
179
current_hospitalized_input = NumberInput (
176
180
st_obj ,
177
181
"Currently hospitalized COVID-19 patients" ,
@@ -349,6 +353,8 @@ def display_sidebar(st, d: Parameters) -> Parameters:
349
353
max_y_axis = max_y_axis_input ()
350
354
351
355
current_date = current_date_input ()
356
+ #Subscribe implementation
357
+ subscribe (st_obj )
352
358
353
359
return Parameters (
354
360
current_hospitalized = current_hospitalized ,
@@ -374,6 +380,66 @@ def display_sidebar(st, d: Parameters) -> Parameters:
374
380
days = ventilated_days ),
375
381
)
376
382
383
+ #Read the environment variables and cteate json key object to use with ServiceAccountCredentials
384
+ def readGoogleApiSecrets ():
385
+ client_secret = {}
386
+ os .getenv
387
+ type = os .getenv ('GAPI_CRED_TYPE' ).strip ()
388
+ print (type )
389
+ client_secret ['type' ] = type ,
390
+ client_secret ['project_id' ] = os .getenv ('GAPI_CRED_PROJECT_ID' ),
391
+ client_secret ['private_key_id' ] = os .getenv ('GAPI_CRED_PRIVATE_KEY_ID' ),
392
+ client_secret ['private_key' ] = os .getenv ('GAPI_CRED_PRIVATE_KEY' ),
393
+ client_secret ['client_email' ] = os .getenv ('GAPI_CRED_CLIENT_EMAIL' ),
394
+ client_secret ['client_id' ] = os .getenv ('GAPI_CRED_CLIENT_ID' ),
395
+ client_secret ['auth_uri' ] = os .getenv ('GAPI_CRED_AUTH_URI' ),
396
+ client_secret ['token_uri' ] = os .getenv ('GAPI_CRED_TOKEN_URI' ),
397
+ client_secret ['auth_provider_x509_cert_url' ] = os .getenv ('GAPI_CRED_AUTH_PROVIDER_X509_CERT_URL' ),
398
+ client_secret ['client_x509_cert_url' ] = os .getenv ('GAPI_CRED_CLIENT_X509_CERT_URI' ),
399
+ json_data = json .dumps (client_secret )
400
+ print (json_data )
401
+ return json_data
402
+
403
+ def readGoogleApiSecretsDict ():
404
+ type = os .getenv ('GAPI_CRED_TYPE' )
405
+ project_id = os .getenv ('GAPI_CRED_PROJECT_ID' )
406
+ private_key_id = os .getenv ('GAPI_CRED_PRIVATE_KEY_ID' )
407
+ private_key = os .getenv ('GAPI_CRED_PRIVATE_KEY' )
408
+ client_email = os .getenv ('GAPI_CRED_CLIENT_EMAIL' )
409
+ client_id = os .getenv ('GAPI_CRED_CLIENT_ID' )
410
+ auth_uri = os .getenv ('GAPI_CRED_AUTH_URI' )
411
+ token_uri = os .getenv ('GAPI_CRED_TOKEN_URI' )
412
+ auth_provider_x509_cert_url = os .getenv ('GAPI_CRED_AUTH_PROVIDER_X509_CERT_URL' )
413
+ client_x509_cert_url = os .getenv ('GAPI_CRED_CLIENT_X509_CERT_URI' )
414
+
415
+ secret = {
416
+ 'type' : type ,
417
+ 'project_id' : project_id ,
418
+ 'private_key_id' : private_key_id ,
419
+ 'private_key' :private_key ,
420
+ 'client_email' : client_email ,
421
+ 'client_id' : client_id ,
422
+ 'auth_uri' : auth_uri ,
423
+ 'token_uri' : token_uri ,
424
+ 'auth_provider_x509_cert_url' :auth_provider_x509_cert_url ,
425
+ 'client_x509_cert_url' :client_x509_cert_url
426
+ }
427
+ return secret
428
+
429
+ def subscribe (st_obj ):
430
+ st_obj .subheader ("Subscribe" )
431
+ email = st_obj .text_input (label = "Enter Email" , value = "" , key = "na_lower_1" )
432
+ name = st_obj .text_input (label = "Enter Name" , value = "" , key = "na_upper_1" )
433
+ affiliation = st_obj .text_input (label = "Enter Affiliation" , value = "" , key = "na_upper_2" )
434
+ if st_obj .button (label = "Submit" , key = "ta_submit_1" ):
435
+ row = [email , name , affiliation ]
436
+ send_subscription_to_google_sheet (st_obj , row )
437
+
438
+ def send_subscription_to_google_sheet (st_obj , row ):
439
+ json_secret = readGoogleApiSecretsDict ()
440
+ #print(json_secret)
441
+ spr = sp .spreadsheet (st_obj , json_secret )
442
+ spr .writeToSheet ("CHIME Form Submissions" , row )
377
443
378
444
def display_footer (st ):
379
445
st .subheader ("References & Acknowledgements" )
0 commit comments