Created
May 10, 2024 13:10
-
-
Save sharpicx/3e7354e4153e9149d229504f246dfb34 to your computer and use it in GitHub Desktop.
grab all tweets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twikit import Client | |
import json | |
import pandas as pd | |
import itertools | |
USERNAME = 'username here' | |
EMAIL = 'email here' | |
PASSWORD = 'password here' | |
client = Client('en-US') | |
client.login( | |
auth_info_1=USERNAME , | |
auth_info_2=EMAIL, | |
password=PASSWORD | |
) | |
client.save_cookies('cookies.json') | |
client.load_cookies('cookies.json') | |
tweets = client.search_tweet('bpjs', 'Top', 20) | |
more_tweets = tweets.next() | |
more_tweets_1 = more_tweets.next() | |
tweets_stored = [] | |
for tweet in itertools.chain(tweets, more_tweets, more_tweets_1): | |
tweets_stored.append({ | |
'name': tweet.user.name, | |
'comment': tweet.text, | |
'created_at': tweet.created_at | |
}) | |
df = pd.DataFrame(tweets_stored) | |
df.to_csv('tweets.csv', index=False) | |
#print(df.sort_values(by='name', ascending=False)) | |
print(json.dumps(tweets_stored)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment