Skip to content

Instantly share code, notes, and snippets.

@isoboroff
Last active July 26, 2018 16:49
Show Gist options
  • Save isoboroff/475705edf6fecce85a4a79f62647d5b0 to your computer and use it in GitHub Desktop.
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.
#!/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