Created
August 28, 2022 14:38
-
-
Save gamingflexer/6875ce4e533132121040ea45177639e8 to your computer and use it in GitHub Desktop.
Twitter Scrapper | Hashtags & User
This file contains 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
# pip3 install --user --upgrade git+https://github.com/twintproject/twint.git@origin/master#egg=twint | |
import os | |
import twint | |
tempath = "add a temp path folder" | |
def top_tweets(username): | |
for user in username: | |
c = twint.Config() | |
c.Limit = 4 | |
c.Min_likes = 1 | |
c.Output = os.path.join(tempath, f"tweets_{user}.json") | |
c.Store_json = True | |
c.Username = user #change to search if u want to scrape from hashtags | |
c.Filter_retweets = True | |
a = twint.run.Search(c) | |
# scrapping done & preprocessing start | |
totalTweets = {} | |
for user in username: | |
tweets = [] | |
for line in open(os.path.join(os.path.join(tempath, f"tweets_{user}.json")), 'r'): | |
tweets.append(json.loads(line)) | |
totalTweets[user] = tweets | |
return totalTweets #returns a json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment