Created
January 9, 2021 01:16
-
-
Save fiatjaf/475b21fc184a027a08e32a8b1b680e3b to your computer and use it in GitHub Desktop.
Save all tweets from someone using https://www.allmytweets.net/ (actually it's limited to 1800 I think)
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
import requests | |
username = 'alexberenson' | |
def write_tweets(f, tweets): | |
for tweet in tweets: | |
text = tweet["full_text"] | |
for url in tweet["entities"]["urls"]: | |
text = text.replace(url["url"], url["expanded_url"]) | |
if quote := tweet.get("quoted_status"): | |
text += f" [QUOTE: {quote['full_text']}]" | |
f.write(f"{tweet['created_at']}: {text}\n\n~> ") | |
with open(f"{username}.tweets", "w") as f: | |
f.write("~> ") | |
for i in range(40): | |
print(i, len(tweets)) | |
if len(tweets) == 0: | |
break | |
tweets = [] | |
max_id = '' | |
if tweets: | |
max_id = tweets[-1]["id"] | |
tweets = requests.get( | |
f"https://www.allmytweets.net/get_tweets.php?count=200&tweet_mode=extended&trim_user&screen_name={username}&max_id={max_id}" | |
).json() | |
if len(tweets) and tweets[0]["id"] == max_id: | |
tweets.pop(0) | |
write_tweets(f, tweets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment