MatteoScript commited on
Commit
cf5dba1
1 Parent(s): ef07441

Update google_function.py

Browse files
Files changed (1) hide show
  1. google_function.py +33 -1
google_function.py CHANGED
@@ -132,7 +132,39 @@ def leggi_calendario_google(max_results=10):
132
  return descrizione_eventi, links
133
 
134
  #---------------------------------------------------------- CONNESSIONE ACCOUNT GOOGLE ---------------------------------------------------------
135
- def connetti_google():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  load_dotenv()
137
  json_variable_str = os.getenv("JSON_GOOGLE")
138
  print(json_variable_str)
 
132
  return descrizione_eventi, links
133
 
134
  #---------------------------------------------------------- CONNESSIONE ACCOUNT GOOGLE ---------------------------------------------------------
135
+ def connetti_google():
136
+ load_dotenv()
137
+ json_variable_str = os.getenv("JSON_GOOGLE")
138
+ print(json_variable_str)
139
+ with open("./credentials.json", "w") as f:
140
+ f.write(json_variable_str)
141
+ if os.path.exists("./credentials.json"):
142
+ print('ESISTE')
143
+ else:
144
+ print('NON ESISTE')
145
+ creds = None
146
+ st.write("Welcome to My App!")
147
+ auth_code = st.query_params.get("code")
148
+ flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri='https://matteoscript-streamlitchat-new.hf.space')
149
+ if auth_code:
150
+ flow.fetch_token(code=auth_code)
151
+ credentials = flow.credentials
152
+ st.write("Login Done")
153
+ user_info_service = build(
154
+ serviceName="oauth2",
155
+ version="v2",
156
+ credentials=credentials,
157
+ )
158
+ user_info = user_info_service.userinfo().get().execute()
159
+ assert user_info.get("email"), "Email not found in infos"
160
+ st.session_state["google_auth_code"] = auth_code
161
+ st.session_state["user_info"] = user_info
162
+ else:
163
+ authorization_url, state = flow.authorization_url(include_granted_scopes="true",)
164
+ print(authorization_url)
165
+ webbrowser.open_new_tab(authorization_url)
166
+
167
+ def connetti_google_2():
168
  load_dotenv()
169
  json_variable_str = os.getenv("JSON_GOOGLE")
170
  print(json_variable_str)