Spaces:
Sleeping
Sleeping
File size: 1,139 Bytes
418b3b9 f889b74 418b3b9 f889b74 418b3b9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# Get the token from the URL
load_dotenv()
secret = os.environ['SECRET']
params = st.experimental_get_query_params()
token = params["token"][0]
# Securely decode the token
try:
decoded = jwt.decode(token, secret, algorithms=["HS512"])
print(decoded)
if decoded["iss"] != "Xponento":
raise Exception("Invalid token")
except Exception as e:
# If this gives an error, the token is invalid
# DONT LOAD THE PAGE, show an error message
st.error("Invalid token")
raise e
companyname = decoded["payload"]["companyname"]
companynreg = decoded["payload"]["companynreg"]
email = decoded["payload"]["email"]
# Connect to the database
cnx = mysql.connector.connect(user=os.environ['USER'], password=os.environ['PASSWORD'], host=os.environ['HOST'], database=os.environ['DATABASE'])
cursor = cnx.cursor()
# Get all financial data for this company
get_financial_data = """
SELECT * FROM fin1 WHERE companyname = %s AND companynreg = %s
"""
cursor.execute(get_financial_data, [companyname, companynreg])
data = cursor.fetchall()
cols = [col[0] for col in cursor.description]
df= pd.DataFrame(data, columns=cols) |