Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Forked from lunasorcery/tweets-media.py
Created November 11, 2022 15:49
Show Gist options
  • Save jpluimers/b1912f65856b941a30bd8b21c3927382 to your computer and use it in GitHub Desktop.
Save jpluimers/b1912f65856b941a30bd8b21c3927382 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import json
with open('tweets.js') as f:
tweets_str = f.read()
# assume the prefix is universally the same ('window.YTD.tweets.part0 = ')
tweets_json = json.loads(tweets_str[26:])
tweets_media = [{
'tweet': {
'id': tweet['tweet']['id'],
'id_str': tweet['tweet']['id_str'],
#'entities': tweet['tweet']['entities'],
'extended_entities': tweet['tweet']['extended_entities'],
}
} for tweet in tweets_json if 'media' in tweet['tweet']['entities']]
with open('./tweets-media.js', 'w') as f:
f.write('window.YTD.tweets.part0 = ')
f.write(json.dumps(tweets_media, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment