Skip to content

Instantly share code, notes, and snippets.

@fiatjaf
Created January 9, 2021 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiatjaf/475b21fc184a027a08e32a8b1b680e3b to your computer and use it in GitHub Desktop.
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)
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