View on GitHub


Reddit 5-7-5 poems

This python program grabs headlines from reddit’s homepage and picks a headline randomly and converts it into a randomized 5-7-5 structured poem

Here YEARS Here 2 undercover
for goes YEARS report. Here is author
YEARS evangelical Atheist is church.

consider understands and seeking understands
service host; want understands want no you
assuming fucking one you’re Lunarpages.

Was Laid Off Obama? Off
Obama? for Obama? Off Employee Was Voting
Voting for Was Off Voting

Cool infographic infographic Nintendo Nintendo
infographic infographic infographic Nintendo Nintendo Cool infographic
infographic Cool Cool Nintendo Cool

[cc lang=”python”]
from BeautifulSoup import BeautifulSoup
import urllib
import random

def haiku(words):

for i in range(0,5):
haiku = random.choice(words)

print ” “.join(haikuList1)

for i in range(0,7):
haiku = random.choice(words)

print ” “.join(haikuList2)

for i in range(0,5):
haiku = random.choice(words)

print ” “.join(haikuList3)

url = “”
titlesList = list()
num = int()
haikuList1 = list()
haikuList2 = list()
haikuList3 = list()

data = urllib.urlopen(url).read()
soup = BeautifulSoup(data)

for tag in soup.findAll(“p”, {“class” : “title”} ):
a = tag.findAll(“a”, {“class” : “title “} )
titles = a[0].string.encode(‘ascii’, ‘ignore’)
titles = titles.strip()
titles = titles.split(” “)

num = random.randrange(0,len(titlesList))
words = titlesList[num]