Skip to content

Instantly share code, notes, and snippets.

@coilysiren
Last active October 12, 2015 13:24
Show Gist options
  • Save coilysiren/8447965d98f8b434808e to your computer and use it in GitHub Desktop.
Save coilysiren/8447965d98f8b434808e to your computer and use it in GitHub Desktop.
# internal
import re
import subprocess
# external
import twython
# prosaic, obviously
twitter = twython.Twython(
ENV['API_KEY'],
ENV['API_SECRET'],
ENV['ACCESS_TOKEN'],
ENV['TOKEN_SECRET'],)
def remove_RTs(string):
return re.sub(r'\bRT\b', '', string, flags=re.IGNORECASE)
def remove_mentions(string):
return re.sub(r'@[A-Z0-9\_]*', '', string, flags=re.IGNORECASE)
def remove_links(string):
return re.sub(r'http.*\b', '', string)
timeline = [str(x['text']) for x in twitter.get_home_timeline(count=200, trim_user=True)]
filename = 'words/{}.txt'.format(twitter.verify_credentials()['screen_name'])
with open(filename, 'w') as f:
for line in timeline:
line = remove_RTs(line)
line = remove_mentions(line)
line = remove_links(line)
f.write(line+'\n')
subprocess.call('prosaic corpus loadfile {}'.format(filename), shell=True)
subprocess.call('prosaic poem new')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment