For my final, I wanted to continue the idea I had for the midterm, but get the poetic form more streamlined, and add a few more items into the mix. Wordnik is one item I wanted to use in order to experiment more with word and their various forms. The markov chain is also something that was added in order to
I wanted to generate song Lyrics, and I wanted them to come from real people. As you know, some of the better songs out there, have been inspired by people’s feelings. So I’m using real people’s feelings, which are scraped from the internet to generate lyrics. Then give them some structure.
In this case, I wanted to experiment with conflicting/opposing feelings – I call them “paranoid” feelings because they make the person look as if they are paranoid.
My project is entitled “The paranoid crooner”
Here is the Output:
#1
VERSE:
I guess maybe this intense feeling that I have been underwater for a very long time, I feel that it may only be temporary.
I feel especially challenged by her – I hear a voice in my head saying.
CHORUS:
I feel good, good, good
I feel bad, bad, bad
I feel bad about feeling good, looking good and have people like me.
#2
VERSE:
I’m still feeling so completely clueless and don’t know what I am doing.
I feel like a rockstar photographer now, so if my pictures still suck please don’t tell me.
I made you, I feel you.
CHORUS:
I feel inspired, inspired, inspired
I feel uninspired, uninspired, uninspired
I feel uninspired about feeling inspired.
#3 – LA
VERSE:
I wake up in the morning and wear what I’m feeling. I didn’t feel any worse than I did that morning when I closed my eyes and meditated. I could feel it inside.
CHORUS:
I feel young, young, young
I feel old, old, old
I feel old about feeling young inside, so I feel like a student when I start a new picture.
#4 – London
VERSE:
I suddenly didn’t feel like I was totally crazy.
I was left standing there in the already scorching sunlight – hungover, feeling like ‘death and loss’
… and alone once more.
CHORUS:
I feel ill, ill, ill
I feel well, well, well
I feel well about feeling ill. I’m a stinking student, what can I do?
#5 – Germany
VERSE:
I think I am in “harry potter-land”.
I can’t even remember the feeling of two weeks doing nothing.
I told him heads would roll if he keeps growling
CHORUS:
I feel black, black, black
I feel white, white, white
I feel white about feeling black and white.
#6 – NYC
VERSE:
I love the light and airy feel …and uhm, yes cupcakes.
I like strawberries, almond chocolate, milky coffee and the feeling of coming back…
CHORUS:
I feel proud, proud, proud
I feel ashamed, ashamed, ashamed
I feel ashamed about feeling proud of this attempt at connecting personally with others through better food.
Here is the code:
#import library to do http requests:
import urllib2
import random
import simple_rhyme_bot
import markov
from time import sleep
counter = 0
feeling_list = []
sentence_list = []
wff_list = []
fulltext = ""
#Wordnik API Key
wordnik_key = "2bf1bdcec*********40868b767b********0136*******a"
#import easy to use xml parser called minidom:
from xml.dom.minidom import parseString
#download the file:
#&city=new+york,ny,nyc
#&city=la,los+angeles
file = urllib2.urlopen('http://api.wefeelfine.org:8080/ShowFeelings?display=xml&returnfields=feeling,sentence&limit=35&city=new+york,ny,nyc')
#convert to string:
data = file.read()
#close file because we dont need it anymore:
file.close()
#parse the xml you downloaded
dom = parseString(data)
#retrieve the XML tag
xmlTags = dom.getElementsByTagName('feeling')
#Markov Generator Function
def make_markov(mytext):
random_n = random.randrange(2,5)
random_max = random.randrange(10,40,5)
generator = markov.MarkovGenerator(n=random_n, max=random_max)
generator.feed(fulltext)
mtext = generator.generate()
return "Random:" + str(random_n) + ":" + str(random_max) + ": " + mtext
#Consolidate all text in one paragraph
for tag in xmlTags:
feeling = tag.getAttribute('feeling')
sentence = tag.getAttribute('sentence')
#Append to List
sentence_list.append(sentence)
wff_list.append([feeling,sentence])
#if len(feeling)>0:
#fulltext = fulltext + sentence + ". "
random_counter = random.randrange(2,8)
print "GENERATED POEM: " + str(random_counter) + " VERSES"
print "-------------------------------"
#Loop through feelings
# for tag in xmlTags:
# feeling = tag.getAttribute('feeling')
# sentence = tag.getAttribute('sentence')
random.shuffle(wff_list)
for tag in wff_list:
feeling = tag[0]
sentence = tag[1]
#If feeling is blank then skip it
if len(feeling)>0:
#Get Antonym
antonym = simple_rhyme_bot.get_paranoid(wordnik_key,feeling)
#rhyme = simple_rhyme_bot.get_rhyming(wordnik_key,feeling)
if antonym:
counter += 1
#Shuffle sentences
random.shuffle(sentence_list)
fulltext = ". ".join(sentence_list)
#Generate Markov Stanza
print "VERSE:"
print make_markov(fulltext)
print "\n"
print "CHORUS:"
paranoid_feeling = antonym[0]
print "I feel " + feeling + ", " + feeling + ", " + feeling
print "I feel " + paranoid_feeling + ", " + paranoid_feeling + ", " + paranoid_feeling
#Print last line from stanza
s = sentence[sentence.find(feeling) + len(feeling):]
print "I feel " + paranoid_feeling + " about feeling " + feeling + s + "."
print "\n"
if counter == random_counter:
break
sleep(1.0)













