#!/usr/bin/env python # coding: utf-8 # ## Sebastian HW Modifications # Original code can be found on Allison Parrish [repo](https://github.com/aparrish/rwet/blob/master/some-poetry-generators.ipynb) # ## Love Letter Generator # # Original by Christopher Strachey, written for the Manchester Mark I in 1952. [Read more here](https://grandtextauto.soe.ucsc.edu/2005/08/01/christopher-strachey-first-digital-artist/). # # Vocabulary based on [this implementation](https://github.com/gingerbeardman/loveletter/blob/master/index.php). # In[1]: sal_adjs = [ "Delicious", "Exquisite", "My", "Juiciest", "Vibrant", "Sweetest"] # In[2]: sal_nouns = [ "Pamplemousse", "Pear", "Guava", "Pommegranade", "Avocado", "Passion Fruit" ] # In[3]: adjsSelf = [ 'affectionate', 'amorous', 'anxious', 'avid', 'beautiful', 'breathless', 'burning', 'covetous', 'craving', 'curious', 'eager', 'fervent', 'fondest', 'loveable', 'lovesick', 'loving', 'passionate', 'precious', 'seductive', 'sweet', 'sympathetic', 'tender', 'unsatisfied', 'winning', 'wistful' ] # In[4]: nounsSelf = [ 'appetite', 'craving', 'desire', 'fancy', 'intestines', 'fervour', 'hunger', 'taste', 'passion', 'tastebuds', 'thirst', 'lips', 'mouth' ] # In[5]: nounsFruit=[ 'shape', 'flavour', 'taste', 'texture', 'peal' ] # In[6]: advsSelf = [ 'affectionately', 'ardently', 'anxiously', 'beautifully', 'burningly', 'covetously', 'curiously', 'eagerly', 'fervently', 'fondly', 'impatiently', 'keenly', 'lovingly', 'passionately', 'seductively', 'tenderly', 'wistfully' ] # In[7]: adjsFruit = [ 'tomato', 'alien', 'delecius', 'perfect', 'bumpy', 'round', 'sweet', 'smooth', 'nectarous', 'crispy' ] # In[8]: verbsSelf = [ 'adores', 'attracts', 'devours', 'holds dear', 'eat for', 'hungers for', 'likes', 'longs for', 'loves', 'lusts after', 'pants for', 'pines for', 'sighs for', 'squeeze', 'thirsts for', 'treasures', 'yearns for', 'woos' ] # In[9]: verbsFruit=[ 'explossion', 'secretion' ] # In[22]: # textwrap library used to "wrap" the text at a particular length import textwrap import random # output begins with salutation output = random.choice(sal_adjs) + " " + random.choice(sal_nouns) + ",\n" output += "\n" # inside this loop, build the phrases. strachey implemented "short" phrases # and "long" phrases; two or more "short" phrases in a row have special # formatting rules, so we need to know what the last phrase kind was in # order to generate the output. history = [] body = "" for i in range(5): kind = random.choice(["short", "long"]) if kind == "long": # adjectives and adverbs will be present only 50% of the time line = " ".join([ "My", random.choice([random.choice(adjsSelf), ""]), random.choice(nounsSelf), random.choice([random.choice(advsSelf), ""]), random.choice(verbsSelf), "your", random.choice([random.choice(adjsFruit), ""]), random.choice(nounsFruit)]) body += line else: adj_noun = random.choice(adjsSelf) + " " + random.choice(nounsSelf) # if the last phrase was "short," use truncated form if len(history) > 0 and history[-1] == "short": body += ": my " + adj_noun else: body += "You are my " + adj_noun body += ". " history.append(kind) # clean up output body = body.replace(" ", " ") body = body.replace(". :", ":") # put everything together output += textwrap.fill(body, 60) output += "\n\nYours " + random.choice(advsSelf) + ",\n" output += "Joe T." print(output)