Update app.py
Browse files
app.py
CHANGED
|
@@ -71,22 +71,23 @@ MOTHERDUCK_TOKEN = st.secrets["MOTHERDUCK_TOKEN"]
|
|
| 71 |
def get_data():
|
| 72 |
try:
|
| 73 |
# Connect to MotherDuck using the token
|
| 74 |
-
# This creates an in-memory connection that links to the cloud DB
|
| 75 |
con = duckdb.connect(f'md:?token={MOTHERDUCK_TOKEN}')
|
| 76 |
|
|
|
|
| 77 |
query = """
|
| 78 |
-
SELECT
|
| 79 |
FROM sentiment_analysis
|
| 80 |
"""
|
| 81 |
|
| 82 |
-
# Execute query and fetch result as a Pandas DataFrame
|
| 83 |
df = con.sql(query).df()
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
# If
|
| 87 |
-
#
|
| 88 |
-
if
|
| 89 |
df["created_at"] = pd.to_datetime(df["created_at"], unit="s")
|
|
|
|
|
|
|
| 90 |
|
| 91 |
return df
|
| 92 |
except Exception as e:
|
|
|
|
| 71 |
def get_data():
|
| 72 |
try:
|
| 73 |
# Connect to MotherDuck using the token
|
|
|
|
| 74 |
con = duckdb.connect(f'md:?token={MOTHERDUCK_TOKEN}')
|
| 75 |
|
| 76 |
+
# Updated query: Removed 'id' based on your schema
|
| 77 |
query = """
|
| 78 |
+
SELECT entity, entity_score, domain, title_score, overall_score, created_at
|
| 79 |
FROM sentiment_analysis
|
| 80 |
"""
|
| 81 |
|
|
|
|
| 82 |
df = con.sql(query).df()
|
| 83 |
|
| 84 |
+
# Robust date handling:
|
| 85 |
+
# If it's numeric (Unix timestamp), convert using unit='s'.
|
| 86 |
+
# If it's already a TIMESTAMP/Datetime object (MotherDuck native), ensure it's standard pandas datetime.
|
| 87 |
+
if pd.api.types.is_numeric_dtype(df["created_at"]):
|
| 88 |
df["created_at"] = pd.to_datetime(df["created_at"], unit="s")
|
| 89 |
+
else:
|
| 90 |
+
df["created_at"] = pd.to_datetime(df["created_at"])
|
| 91 |
|
| 92 |
return df
|
| 93 |
except Exception as e:
|