Spaces:
Sleeping
Sleeping
| # 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) |