Last active
July 26, 2018 16:49
-
-
Save isoboroff/475705edf6fecce85a4a79f62647d5b0 to your computer and use it in GitHub Desktop.
Convert a file of tweets into a file of fortunes as used by Unix fortune(1) and Emacs cookie-mode.
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
#!/usr/bin/env python3 | |
import json | |
import argparse | |
import re | |
# source files from https://github.com/bpb27/trump_tweet_data_archive | |
# Removes URLs since M-x cookie-doctor gets confused by them | |
argparser = argparse.ArgumentParser(description='Convert from JSON array of condensed tweets to cookie format') | |
argparser.add_argument('file', help='JSON file') | |
args = argparser.parse_args() | |
with open(args.file, 'rb') as fp: | |
tweets = json.load(fp) | |
for t in tweets: | |
content = t['text'] | |
content = re.sub(r"http\S+", "", content) | |
print(content, end='\0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment