wira.indra commited on
Commit
b99df17
1 Parent(s): d990ea1

add twitter feature

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. twitter_scraper.py +15 -4
app.py CHANGED
@@ -72,8 +72,8 @@ if __name__ == "__main__":
72
  with gr.Row():
73
  with gr.Column():
74
  input_text = gr.Textbox(label="Input Text")
75
- examples_bar = gr.Examples(examples=examples, inputs=input_text)
76
  analyze_button = gr.Button(label="Analyze")
 
77
  with gr.Column():
78
  sent_output = gr.Label(label="Sentiment Analysis")
79
  ner_output = gr.HighlightedText(label="Named Entity Recognition")
 
72
  with gr.Row():
73
  with gr.Column():
74
  input_text = gr.Textbox(label="Input Text")
 
75
  analyze_button = gr.Button(label="Analyze")
76
+ examples_bar = gr.Examples(examples=examples, inputs=input_text)
77
  with gr.Column():
78
  sent_output = gr.Label(label="Sentiment Analysis")
79
  ner_output = gr.HighlightedText(label="Named Entity Recognition")
twitter_scraper.py CHANGED
@@ -7,10 +7,21 @@ import tqdm
7
  def scrape_tweets(query, max_tweets=10, output_path="./scraper/output/" ):
8
  tweets_list = []
9
 
10
- for i,tweet in tqdm(enumerate(sntwitter.TwitterSearchScraper(query).get_items())):
11
- if max_tweets != -1 and i >= int(max_tweets):
12
- break
13
- tweets_list.append([tweet.date, tweet.id, tweet.content, tweet.user.username, tweet.likeCount, tweet.retweetCount, tweet.replyCount, tweet.quoteCount, tweet.url, tweet.lang])
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  df = pd.DataFrame(tweets_list, columns=['Datetime', 'Tweet Id', 'Text', 'Username', 'Likes', 'Retweets', 'Replies', 'Quotes', 'URL', 'Language'])
16
  df = df[df["Language"] == "in"]
 
7
  def scrape_tweets(query, max_tweets=10, output_path="./scraper/output/" ):
8
  tweets_list = []
9
 
10
+ tweets_list = []
11
+ if sys.version_info.minor>=8:
12
+ for i,tweet in tqdm(enumerate(sntwitter.TwitterSearchScraper(query).get_items())):
13
+ if max_tweets != -1 and i >= int(max_tweets):
14
+ break
15
+ tweets_list.append([tweet.date, tweet.id, tweet.content, tweet.user.username, tweet.likeCount, tweet.retweetCount, tweet.replyCount, tweet.quoteCount, tweet.url, tweet.lang])
16
+
17
+ df = pd.DataFrame(tweets_list, columns=['Datetime', 'Tweet Id', 'Text', 'Username', 'Likes', 'Retweets', 'Replies', 'Quotes', 'URL', 'Language'])
18
+ df = df[df["Language"] == "in"]
19
+ else:
20
+ for i,tweet in tqdm(enumerate(sntwitter.TwitterSearchScraper(query).get_items())):
21
+ if max_tweets != -1 and i >= int(max_tweets):
22
+ break
23
+ tweets_list.append([tweet.date, tweet.id, tweet.content])
24
+ df = pd.DataFrame(tweets_list, columns=['Datetime', 'Tweet Id', 'Text'])
25
 
26
  df = pd.DataFrame(tweets_list, columns=['Datetime', 'Tweet Id', 'Text', 'Username', 'Likes', 'Retweets', 'Replies', 'Quotes', 'URL', 'Language'])
27
  df = df[df["Language"] == "in"]