Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from random import random, choice
- from time import sleep
- from tweepy import API, OAuthHandler, TweepError
- from datetime import datetime
- def flip():
- return random() < 0.5
- def pick(seq):
- return str.strip(choice(seq))
- def pluralize(word):
- if word[-1] is 's':
- return word + 'es'
- elif word[-1] is 'y' and word not in ['tity', 'tiddy']:
- return word[:-1] + 'ies'
- else:
- return word + 's'
- def condplural(word):
- return pluralize(word) if flip() else word
- def withso(seq):
- def so_inner(word):
- return 'so ' + word
- return map(so_inner, seq)
- consumer_key = 'consumer key goes here'
- consumer_secret = 'consumer secret goes here'
- access_token = 'access token goes here'
- access_secret = 'access secret goes here'
- auth = OAuthHandler(consumer_key, consumer_secret)
- auth.set_access_token(access_token, access_secret)
- api = API(auth)
- while True:
- nouns = open('C:/Users/rich_sky/Documents/slime/nouns1.txt').readlines()
- actions = open('C:/Users/rich_sky/Documents/slime/actions1.txt').readlines()
- verbs = open('C:/Users/rich_sky/Documents/slime/verbs1.txt').readlines()
- adjectives = open('C:/Users/rich_sky/Documents/slime/adjectives1.txt').readlines()
- phrases = open('C:/Users/rich_sky/Documents/slime/phrases1.txt').readlines()
- reasons = open('C:/Users/rich_sky/Documents/slime/reasons1.txt').readlines()
- superlatives = open('C:/Users/rich_sky/Documents/slime/superlatives1.txt').readlines()
- hearts = [u'\u2764', u'\U0001f495', u'\U0001f496', u'\U0001f497', u'\U0001f499',
- u'\U0001f49a', u'\U0001f49b', u'\U0001f49c', u'\U0001f49d']
- phrase = pick(phrases)
- while '{' in phrase:
- oldphrase = phrase[:]
- phrase = phrase.replace('{noun}', pick(nouns), 1)
- phrase = phrase.replace('{noun:s}', pluralize(pick(nouns)), 1)
- phrase = phrase.replace('{noun:s?}', condplural(pick(nouns)), 1)
- phrase = phrase.replace('{verb}', pick(verbs), 1)
- phrase = phrase.replace('{action}', pick(actions), 1)
- phrase = phrase.replace('{adjective}', pick(adjectives), 1)
- phrase = phrase.replace('{reason}', pick(reasons), 1)
- phrase = phrase.replace('{superlative}', pick(superlatives), 1)
- phrase = phrase.replace('{adjective:super}', pick(adjectives + superlatives), 1)
- phrase = phrase.replace('{adjective:sosuper}', pick(withso(adjectives) + superlatives), 1)
- if phrase == oldphrase:
- raise RuntimeError('Malformed phrase: %s' % phrase)
- phrase = phrase.replace('<3', choice(hearts))
- print('%s %s' % (datetime.now(), phrase))
- try:
- api.update_status(phrase)
- except TweepError as e:
- print(' failed: %s' % e.message)
- continue
- sleep(1500)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement