Spaces:
Running
Running
Update google_function.py
Browse files138 unmodified lines1391401411421431441451461471481491501511521531541551563 unmodified lines16016116216316416516622 unmodified lines189190191192193194195138 unmodified linesreturn st_javascript(f"localStorage.setItem('{key}', '{value}');")def connetti_google():redirect = 'https://matteoscript-streamlitchat-new.hf.space'load_dotenv()json_variable_str = os.getenv("JSON_GOOGLE")with open("./credentials.json", "w") as f:f.write(json_variable_str)flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri=redirect)token = local_storage_get("token")print('------------1------------------')print(token)if token and token != '':print('------------2------------------')#local_storage_set("token", '')flow.fetch_token(code=token)st.session_state.creds = flow.credentialsprint(st.session_state.creds)3 unmodified linesauth_code = st.query_params.get("code")if auth_code:local_storage_set("token", auth_code)time.sleep(2)print('**************************************************************')print(auth_code)nav_script = """<meta http-equiv="refresh" content="0; url='%s'">""" % (redirect)22 unmodified linesif creds and creds.expired and creds.refresh_token:creds.refresh(Request())else:flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri='https://matteoscript-streamlitchat-new.hf.space')#creds = flow.run_local_server(port=8501, open_browser=False)creds = flow.run_console()with open("token.json", "w") as token:138 unmodified lines1391401411421431441451461471481491501511521531541553 unmodified lines15916016116216316416522 unmodified lines188189190191192193194138 unmodified linesreturn st_javascript(f"localStorage.setItem('{key}', '{value}');")def connetti_google():load_dotenv()json_variable_str = os.getenv("JSON_GOOGLE")URL_REDIRECT = os.getenv('URL_REDIRECT')with open("./credentials.json", "w") as f:f.write(json_variable_str)flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri=URL_REDIRECT)token = local_storage_get("token")print('------------1------------------')print(token)if token and token != '':print('------------2------------------')flow.fetch_token(code=token)st.session_state.creds = flow.credentialsprint(st.session_state.creds)3 unmodified linesauth_code = st.query_params.get("code")if auth_code:local_storage_set("token", auth_code)time.sleep(0.7)print('**************************************************************')print(auth_code)nav_script = """<meta http-equiv="refresh" content="0; url='%s'">""" % (redirect)22 unmodified linesif creds and creds.expired and creds.refresh_token:creds.refresh(Request())else:flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri=URL_REDIRECT)#creds = flow.run_local_server(port=8501, open_browser=False)creds = flow.run_console()with open("token.json", "w") as token:
google_function.py+4-5