Spaces:
Runtime error
Runtime error
Commit
·
ef02346
1
Parent(s):
090b13e
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,7 +73,7 @@ def get_accounts() -> List[dict]:
|
|
| 73 |
|
| 74 |
|
| 75 |
@app.get("/tweets/{username}")
|
| 76 |
-
def get_tweets(username: str) -> dict:
|
| 77 |
# if username in username_list:
|
| 78 |
# query = f"from:{username} since:{start_date} until:{end_date}"
|
| 79 |
# return ts.get_tweets(query=query)
|
|
@@ -81,13 +81,17 @@ def get_tweets(username: str) -> dict:
|
|
| 81 |
# return {"detail": "Account not in scope of project."}
|
| 82 |
if username in username_list:
|
| 83 |
df_tweets = get_latest_account_tweets(username)
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
else:
|
| 92 |
return {"detail": "Account not in scope of project."}
|
| 93 |
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
@app.get("/tweets/{username}")
|
| 76 |
+
async def get_tweets(username: str) -> dict:
|
| 77 |
# if username in username_list:
|
| 78 |
# query = f"from:{username} since:{start_date} until:{end_date}"
|
| 79 |
# return ts.get_tweets(query=query)
|
|
|
|
| 81 |
# return {"detail": "Account not in scope of project."}
|
| 82 |
if username in username_list:
|
| 83 |
df_tweets = get_latest_account_tweets(username)
|
| 84 |
+
if isinstance(df_tweets, pd.DataFrame):
|
| 85 |
+
print(df_tweets.head(2))
|
| 86 |
+
print(df_tweets.shape)
|
| 87 |
+
df_tweets = df_tweets[['handle','created_at','full_text']]
|
| 88 |
+
df_tweets = df_tweets.sort_values('created_at',ascending=True).tail(10)
|
| 89 |
+
df_tweets_html = df_tweets.to_html(classes="center", index=False)
|
| 90 |
+
|
| 91 |
+
return HTMLResponse(content=df_tweets_html, status_code=200)
|
| 92 |
+
else:
|
| 93 |
+
print("Error: Failed to retrieve tweets.")
|
| 94 |
+
return df_tweets
|
| 95 |
else:
|
| 96 |
return {"detail": "Account not in scope of project."}
|
| 97 |
|