-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtweetscraper.py
More file actions
38 lines (19 loc) · 857 Bytes
/
Copy pathtweetscraper.py
File metadata and controls
38 lines (19 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# coding: utf-8
# In[1]:
get_ipython().system('pip install git+https://github.com/JustAnotherArchivist/snscrape.git')
# In[1]:
import snscrape.modules.twitter as sntwitter
import pandas as pd
# In[14]:
def tweets(username,since,upto,maxtweets):
maxTweets = maxtweets
tweets_list = []
# Using TwitterSearchScraper to scrape data and append tweets to list
for i,tweet in enumerate(sntwitter.TwitterSearchScraper('from:{0} since:{1} until:{2}'.format(username,since,upto)).get_items()):
if i>maxTweets:
break
tweets_list.append([tweet.date, tweet.id, tweet.rawContent, tweet.user.username])
tweets_df = pd.DataFrame(tweets_list, columns=['Datetime', 'Tweet Id', 'Text', 'Username'])
tweets_df.to_csv('{0}.csv'.format(username), sep=',', index=False)
return tweets_df