aus10powell commited on
Commit
eeaff04
1 Parent(s): c8433b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -6,6 +6,9 @@ or
6
  import datetime as dt
7
  import json
8
  import logging
 
 
 
9
  import numpy as np
10
  import os
11
  import random
@@ -19,11 +22,12 @@ from fastapi.templating import Jinja2Templates
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
26
-
27
  logging.basicConfig(level=logging.INFO)
28
 
29
  app = FastAPI()
@@ -73,27 +77,30 @@ def get_accounts() -> List[dict]:
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)
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
- 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
 
98
 
99
  @app.get("/audience/{username}", response_model=dict)
 
6
  import datetime as dt
7
  import json
8
  import logging
9
+ import sys
10
+ #sys.setrecursionlimit(20000)
11
+ import pandas as pd
12
  import numpy as np
13
  import os
14
  import random
 
22
 
23
  import scripts.sentiment as sentiment
24
  import scripts.twitter_scraper as ts
25
+ from scripts.summarization import bert_summarization
26
  from scripts.twitter_scraper import get_latest_account_tweets
27
+ from scripts import twitter_scraper as ts
28
  import scripts.utils as utils
29
  from scripts import generative
30
  import nltk
 
31
  logging.basicConfig(level=logging.INFO)
32
 
33
  app = FastAPI()
 
77
 
78
 
79
  @app.get("/tweets/{username}")
80
+ def get_tweets_username(username: str) -> dict:
81
  # if username in username_list:
82
  # query = f"from:{username} since:{start_date} until:{end_date}"
83
  # return ts.get_tweets(query=query)
84
  # else:
85
  # return {"detail": "Account not in scope of project."}
86
+
87
+ # Method 1: Using Tweepy method
88
+ # df_tweets = get_latest_account_tweets(username)
89
+
90
+ # Method 2: Use Snscrape
91
+ df_tweets = ts.get_tweets(handle=username)
92
+
93
+ if isinstance(df_tweets, pd.DataFrame):
94
+ print(df_tweets.head(2))
95
+ print(df_tweets.shape)
96
+ df_tweets = df_tweets[["handle", "created_at", "full_text"]]
97
+ df_tweets = df_tweets.sort_values("created_at", ascending=True).tail(10)
98
+ df_tweets_html = df_tweets.to_html(classes="center", index=False)
99
+
100
+ return HTMLResponse(content=df_tweets_html, status_code=200)
101
  else:
102
+ print("Error: Failed to retrieve tweets.")
103
+ return df_tweets
104
 
105
 
106
  @app.get("/audience/{username}", response_model=dict)