Exemplo n.º 1
0
def run():
    # set up eulagizer
    gizer = Eulagizer('corpus')

    # initialize
    tweet = None

    # 20 attempts to generate real tweet
    for i in range(20):
        # make eula
        try:
            eula = gizer.run(length=500,
                             product='Eulagizer', company='Central Headquarters',
                             website='github.com/aschn/eulagizer')
        except RuntimeError:
            continue

        # split into sentences
        sentences = [s.strip()+'.' for s in eula.split('.')]

        # select sentences between 20 and 139 characters
        choices = filter(lambda s: len(s) > 20 and len(s) < 140, sentences)

        # if choices exist, choose one
        if choices:
            tweet = random.choice(choices)
            break

    # send tweet
    if tweet:
        api = twitter.Api(consumer_key=os.environ.get('TWITTER_CONSUMER_KEY'),
                          consumer_secret=os.environ.get('TWITTER_CONSUMER_SECRET'),
                          access_token_key=os.environ.get('TWITTER_ACCESS_KEY'),
                          access_token_secret=os.environ.get('TWITTER_ACCESS_SECRET'))
        api.PostUpdate(tweet)

    # return
    return tweet
Exemplo n.º 2
0
# import class
from eulagizer import Eulagizer

# create an instance and load contents of corpus directory
gizer = Eulagizer('corpus')

# optional: add an additional file to corpus
#gizer.add_to_corpus('path/to/other.txt')

# generate EULA text string
# length is the minimum number of words, other parameters are self-explanatory
# feel free to run this repeatedly until you get one you like :)
eula_text = gizer.run(length=500, product='Eulagizer',
                      company='Central Headquarters', website='company.com')

# optional: write to file
with open('test.txt', 'w') as f:
    f.write(eula_text)