Created
April 5, 2024 23:50
-
-
Save marceloexc/02a8aa4c3fbbc0fb3897f07d3ead0554 to your computer and use it in GitHub Desktop.
A python script to export saved tweet URL's in Squawker's backup file to a text file
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
# This script is intended for files created with https://github.com/j-fbriere/squawker | |
# In order for this to work, you must select "Export Tweets" when exporting your Squawker data! | |
import argparse | |
import json | |
from pathlib import Path | |
def main(input_file, output_file): | |
tweet_urls = [] | |
with Path(input_file).open() as source: | |
objects = json.load(source) | |
for index, tweets in enumerate(objects['tweets']): | |
tweet_content_as_dict = json.loads(tweets['content']) | |
screen_name = tweet_content_as_dict["user"]["screen_name"] | |
status_string = tweet_content_as_dict["id_str"] | |
tweet_url = ("https://x.com/" + screen_name + "/status/" + status_string) | |
tweet_urls.append(tweet_url) | |
with Path(output_file).open('w') as file: | |
file.write('\n'.join(tweet_urls)) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="extract tweet URLs from JSON file.") | |
parser.add_argument("input_file", type=str, help="input path of squawker .json file") | |
parser.add_argument("output_file", type=str, help="output path of text file to be created") | |
args = parser.parse_args() | |
main(args.input_file, args.output_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment