sbgonenc96 commited on
Commit
199c939
·
verified ·
1 Parent(s): 00155bb

update getting secrets

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -2,17 +2,32 @@ import gspread
2
  from oauth2client.service_account import ServiceAccountCredentials
3
  import streamlit as st
4
  import re
5
-
 
6
 
7
  # Page Configuration
8
  st.set_page_config(page_title="FurOmics", page_icon="🐾", layout="centered")
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Function to add email to Google Sheets
11
  def add_email_to_sheet(email):
 
 
12
  try:
13
  # Set up Google Sheets API client
14
  scopes = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
15
- creds = ServiceAccountCredentials.from_json_keyfile_dict(st.secrets["google"], scopes)
16
  client = gspread.authorize(creds)
17
 
18
  # Open the sheet and append the email
@@ -42,7 +57,7 @@ st.subheader("COMING SOON!")
42
  st.header("Join Our Waitlist")
43
  email = st.text_input("Enter your email to stay updated:")
44
  if st.button("Join Waitlist"):
45
- if email and re.match(r"^[a-z0-9]+@[^@]+\.[a-z]+$", email):
46
  success = add_email_to_sheet(email)
47
  if success:
48
  st.success("Thank you for joining the waitlist!")
 
2
  from oauth2client.service_account import ServiceAccountCredentials
3
  import streamlit as st
4
  import re
5
+ import json
6
+ import os
7
 
8
  # Page Configuration
9
  st.set_page_config(page_title="FurOmics", page_icon="🐾", layout="centered")
10
 
11
+ def get_google_keys():
12
+ google_secrets = st.secrets["google"]
13
+ if google_secrets is None:
14
+ google_secrets = os.getenv("google", None)
15
+ if isinstance(google_secrets, str):
16
+ google_secrets = json.loads(google_secrets)
17
+
18
+ if google_secrets is None:
19
+ raise Exception("google api keys could not be initialized")
20
+
21
+ return google_secrets
22
+
23
  # Function to add email to Google Sheets
24
  def add_email_to_sheet(email):
25
+ google_secrets = get_google_keys()
26
+
27
  try:
28
  # Set up Google Sheets API client
29
  scopes = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
30
+ creds = ServiceAccountCredentials.from_json_keyfile_dict(google_secrets, scopes)
31
  client = gspread.authorize(creds)
32
 
33
  # Open the sheet and append the email
 
57
  st.header("Join Our Waitlist")
58
  email = st.text_input("Enter your email to stay updated:")
59
  if st.button("Join Waitlist"):
60
+ if email and re.match(r"^[a-z0-9_-]+@[^@]+\.[a-z]+$", email):
61
  success = add_email_to_sheet(email)
62
  if success:
63
  st.success("Thank you for joining the waitlist!")