aus10powell commited on
Commit
1cac62c
1 Parent(s): 59b85d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -19,6 +19,7 @@ from fastapi.templating import Jinja2Templates
19
 
20
  import scripts.sentiment as sentiment
21
  import scripts.twitter_scraper as ts
 
22
  import scripts.utils as utils
23
  from scripts import generative
24
  import nltk
@@ -66,14 +67,27 @@ def get_accounts() -> List[dict]:
66
  df_account = df_account.format(
67
  {"follower_count": "{:,.0f}", "friends_count": "{:,.0f}"}
68
  )
69
- return HTMLResponse(content=df_account.to_html(classes="center"), status_code=200)
70
 
 
71
 
72
- @app.get("/tweets/{username}", response_model=dict)
 
73
  def get_tweets(username: str) -> dict:
 
 
 
 
 
74
  if username in username_list:
75
- # query = f"from:{username} since:{start_date} until:{end_date}"
76
- return ts.get_tweets(query=query)
 
 
 
 
 
 
77
  else:
78
  return {"detail": "Account not in scope of project."}
79
 
 
19
 
20
  import scripts.sentiment as sentiment
21
  import scripts.twitter_scraper as ts
22
+ from scripts.twitter_scraper import get_latest_account_tweets
23
  import scripts.utils as utils
24
  from scripts import generative
25
  import nltk
 
67
  df_account = df_account.format(
68
  {"follower_count": "{:,.0f}", "friends_count": "{:,.0f}"}
69
  )
70
+ html_table = df_account.to_html(classes="center", index=False)
71
 
72
+ return HTMLResponse(content=html_table, status_code=200)
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)
80
+ # else:
81
+ # return {"detail": "Account not in scope of project."}
82
  if username in username_list:
83
+ df_tweets = get_latest_account_tweets(username)
84
+ print(df_tweets.head(2))
85
+ print(df_tweets.shape)
86
+ df_tweets = df_tweets[['handle','created_at','full_text','id']]
87
+ df_tweets = df_tweets.sort_values('created_at',ascending=True).tail(20)
88
+ df_tweets_html = df_tweets.to_html(classes="center", index=False)
89
+
90
+ return HTMLResponse(content=df_tweets_html, status_code=200)
91
  else:
92
  return {"detail": "Account not in scope of project."}
93