View on GitHub

oddgui

Reading and Writing Text Homework 1

For this homework I wanted to mashup 3 Charles Bukowski programs and make them adorable. I started with 3 poems: Death wants more Death, The Riot, and Two Kinds of Hell.

I started with

cat deathwantsmoredeath.txt theriot.txt twokindsofhell.txt

This is how I combined multiple files.

I ran python hwfeb05.py <charles#.txt>charles#.txt with the pound being increasing numbers from 0-5

This is the code for hwfeb05.py this code divides the poem in half
[cc lang=”python”]
import sys

count = 0

for line in sys.stdin:

line = line.strip()

if count % 2 == 0:

output = line

else:

output = “”

print output

count += 1
[/cc]
Then I ran python  hwfeb05replace.py< charles5.txt>charlesreplace.txt

Here is  the code for hwfeb05replace.py. This replace code is what looks for the words I want to make adorable.
[cc lang=”python”]]
import sys

for line in sys.stdin:
line = line.strip()
line = line.replace(‘death’, ‘pandas’)
line = line.replace(‘corpses’, ‘puppies’)
line = line.replace(‘corpse’, ‘puppy’)
line = line.replace(‘drink’, ‘hug’)
line = line.replace(‘dark’, ‘puppy-eyed’)
line = line.replace(‘drinks’, ‘hugs’)
line = line.replace(‘ladies’, ‘unicorns’)
line = line.replace(‘lady’, ‘unicorn’)
line = line.replace(‘crime’,’party’)
line = line.replace(‘enemy’,’buddy’)
line = line.replace(‘enemies’,’buddies’)
line = line.replace(‘bar’,’playground’)
line = line.replace(‘alone’,’holding hands’)
line = line.replace(‘body’,’kitten’)
line = line.replace(‘bodies’,’kittens’)
print line

[/cc]

Finally I ran python hwfeb05finder.pycharlesfinder.txt

[cc lang=”python”]
import sys
for line in sys.stdin:
line = line.strip()
offset = line.find(“pandas”)
if offset != -1:
print line
offset = line.find(“puppies”)
if offset != -1:
print line
offset = line.find(“puppy”)
if offset != -1:
print line
offset = line.find(“hug”)
if offset != -1:
print line
offset = line.find(“puppy-eyed”)
if offset != -1:
print line
offset = line.find(“hugs”)
if offset != -1:
print line
offset = line.find(“unicorns”)
if offset != -1:
print line
offset = line.find(“unicorn”)
if offset != -1:
print line
offset = line.find(“party”)
if offset != -1:
print line
offset = line.find(“buddy”)
if offset != -1:
print line
offset = line.find(“buddies”)
if offset != -1:
print line
offset = line.find(“playground”)
if offset != -1:
print line
offset = line.find(“holding hands”)
if offset != -1:
print line
offset = line.find(“kitten”)
if offset != -1:
print line
offset = line.find(“kittens”)
if offset != -1:
print line

[/cc]
That gave me this output:

pandas wants more pandas, and its webs are full:
I would brush the puppies of flies
their sticky, ugly, vibrant kittens
their sticky, ugly, vibrant kittens
towards some puppy-eyed corner
towards some puppy-eyed corner
I sat in the same playground for 7 years, from 5 a.m.
I had no money but the hugs kept
I had no money but the hugs kept
to them I wasn’t the playground clown
and I began to hug holding hands and I found the company
and I began to hug holding hands and I found the company
heart, knocks began upon my door: unicorns
heart, knocks began upon my door: unicorns
and the unicorns arrived one at a time and when it ended with
and the unicorns arrived one at a time and when it ended with
but I remembered the 7 years in the playground, I hardly ever bedded
his simple strength and salvation, they will send the unicorn
and then you remember the playground
somekitten in the playground saying: “hey, sir, forget it, he’s a mental
somekitten in the playground saying: “hey, sir, forget it, he’s a mental
gods arranged to get all those unicorns knocking and you went for
gods arranged to get all those unicorns knocking and you went for
the puff of kitten swelling
looking for the buddy
saw or sensed my party

The only thing that I need to figure out now is how not to print out duplicate lines