Spaces:
Runtime error
Runtime error
Update google_function.py
Browse files10 unmodified lines111213141516174 unmodified lines22232425262728295 unmodified lines3536373538394037 unmodified lines7879807981828314 unmodified lines989910010010110210329 unmodified lines13313413513613713813914014114214314413914514614214314414514614714814715015114814915015115215315415515615715815915515615715816016116216316416516616716816917017117217310 unmodified linesfrom bs4 import BeautifulSoupimport webbrowserimport datetimefrom streamlit_javascript import st_javascriptimport streamlit as st
SCOPES = ["https://www.googleapis.com/auth/gmail.compose", 4 unmodified lines "https://www.googleapis.com/auth/forms.body", "https://www.googleapis.com/auth/spreadsheets.readonly"]
creds = None
#---------------------------------------------------------- LETTURA EMAIL ---------------------------------------------------------def converti_email_txt(body): try:5 unmodified lines return body
def leggi_gmail(max_results=10): creds=connetti_google() links = [] service = build("gmail", "v1", credentials=creds) results = service.users().messages().list(userId="me", labelIds=["INBOX"], q="is:unread", maxResults=max_results).execute()37 unmodified lines#---------------------------------------------------------- SCRITTURA BOZZA EMAIL --------------------------------------------------------- def scrivi_bozza_gmail(testo): draft_url = '' creds=connetti_google() try: service = build("gmail", "v1", credentials=creds) message = EmailMessage()14 unmodified lines
#---------------------------------------------------------- LEGGI GOOGLE CALENDAR --------------------------------------------------------- def leggi_calendario_google(max_results=10): creds=connetti_google() try: service = build("calendar", "v3", credentials=creds) calendar_list_result = service.calendarList().list().execute()29 unmodified lines return descrizione_eventi, links
#---------------------------------------------------------- CONNESSIONE ACCOUNT GOOGLE ---------------------------------------------------------def local_storage_get(key): return st_javascript(f"localStorage.getItem('{key}');")
def local_storage_set(key, value): return st_javascript(f"localStorage.setItem('{key}', '{value}');")
def connetti_google(): load_dotenv() json_variable_str = os.getenv("JSON_GOOGLE") print(json_variable_str) with open("./credentials.json", "w") as f: f.write(json_variable_str) if os.path.exists("./credentials.json"): print('ESISTE') else: print('NON ESISTE') creds = None st.write("Welcome to My App!") auth_code = st.query_params.get("code") flow = InstalledAppFlow.from_client_secrets_file("./credentials.json", SCOPES, redirect_uri='https://matteoscript-streamlitchat-new.hf.space') if auth_code: flow.fetch_token(code=auth_code) token = local_storage_get("token") print('------------1------------------') print(token) if token and token != '': print('------------2------------------') local_storage_set("token", '') flow.fetch_token(code=token) creds = flow.credentials print(creds) st.write("Login Done") st.session_state.login_effettuato = True else: authorization_url, state = flow.authorization_url(include_granted_scopes="true",) print(authorization_url) st.markdown(f'<a href="{authorization_url}">Click here to sign in with Google</a>', unsafe_allow_html=True) return creds print('------------3------------------') auth_code = st.query_params.get("code") if auth_code: local_storage_set("token", auth_code) st_javascript('window.location.href = "https://matteoscript-streamlitchat-new.hf.space";') else: print('------------4------------------') st.write("") authorization_url, state = flow.authorization_url(include_granted_scopes="true",) st.write('## Login Bonsi A.I.') st.markdown(f'<a href="{authorization_url}" target="_self">Effettua Login Google</a>', unsafe_allow_html=True)
def connetti_google_2(): load_dotenv()google_function.py+29-17