Monday, May 20, 2013
Monday, April 22, 2013
Final: Too good to be news
http://toogoodtobenews.com
Too good to be news is a realtime poetry generator based on news feeds and verses. The app grabs current headlines from The New York Times and National Public Radio RSS feeds. In addition, I made a file that has a collection of verses written by Charles Simic, a Serbian-American poet and Pulitzer-Prize laureate. The source structures look like this:
1) New York Times
2) Charles Simic
3) National Public Radio
4) Charles Simic
In order to parse the data, I employed a Python library called BeautifulSoup (thank you Adam!)
Steps
1) Grab the data from the previously mentioned URLs.
i.e
2) Define a list for each service (NYT, NPR, Simic)
3) Locate the tag to be parsed.
4) Declare None in case of empty results.
5) Append the headlines to the list.
6) Randomly shuffle the list.
7) Pick one sentence and print the result.
8) Apply the same procedure to every source of information.
9) Test the Python code in terminal.
11) Refine the CSS.
12) Smile, celebrate and do some Google search. If you happen to find the Heroku sever, you will get a nice suprise!

Too good to be news is a realtime poetry generator based on news feeds and verses. The app grabs current headlines from The New York Times and National Public Radio RSS feeds. In addition, I made a file that has a collection of verses written by Charles Simic, a Serbian-American poet and Pulitzer-Prize laureate. The source structures look like this:
1) New York Times
2) Charles Simic
3) National Public Radio
4) Charles Simic
In order to parse the data, I employed a Python library called BeautifulSoup (thank you Adam!)
Steps
1) Grab the data from the previously mentioned URLs.
i.e
2) Define a list for each service (NYT, NPR, Simic)
3) Locate the tag to be parsed.
4) Declare None in case of empty results.
5) Append the headlines to the list.
6) Randomly shuffle the list.
7) Pick one sentence and print the result.
8) Apply the same procedure to every source of information.
9) Test the Python code in terminal.
10) Build an app and deploy it to a server. If everything works well, work on the aesthetic side and styles.

Wednesday, April 17, 2013
Friday, March 15, 2013
Midterm | PoeSys
PoeSys is an app written in Python, Flask and CSS that produces a random poem each time the app/website is accessed. The embedded dictionary has 30 original verses that I wrote "from scratch". This generator can output 1000 different poems. The app uses the random (re) library. Other libraries and databases (i.e. mongo) were removed from the current code in order to make it cleaner.
Wednesday, February 20, 2013
Assignment # 2
Write a program that reads in and creatively re-arranges the content of one or more source texts. What is the unit of your cut-up technique? (the word, the line, the character? something else?) How does your procedure relate (if at all) to your choice of source text? Feel free to build on your assignment from last week. Your program must make use of at least one set, dictionary, or list.
Idea
Since next class we'll be talking about OuLiPo, I decided to write a python program that randomly grabs sentences from a dictionary that has 14 lists comprised by 10 lines each. This is the basis of the book Cent mille milliards de poèmes (A Hundred Thousand Billion Poems) by French poet and novelist, Raymond Queneau.
Process
The program displays 14 sentences out of 140 lines. From a mathematical perspective, if we multiply 14 times 10 (10x10x10x10x10x10x10x10x10x10x10x10x10x10) we'll obtain a beautiful large number: 100.000.000.000.000 (one hunded billion). In short, 1014
After a tedious search, I found a couple of english translations of Queneau's sentences. One of the versions looked like it was translated using an old french-english computer translator. I employed Google Translator to translate and verify the last group of lines. The differences were remarkable.
Additionally, I assigned a number to each line of each list. Hence, when running the program the user will recognize not only the selected random sentences, but also the number of the outputted combination.
Code
Results
9 One's left with only sorrow and disease
4 He's cast out like a snobby Romeo
5 He'd much to learn despite his four degrees
0 So stink the rotting skins from long ago
1 The Parthenon horse is shivering in the bise
7 The mob demands that verse be comme il faut
8 Mixing broom with chives shows expertise
8 But offering kids a sweetie that's no-no
2 The inspired poet isn't polyglot
8 In his brain one tongue is all he's got
2 While coming home we find the wind turned mean
1 Its famous sculptures founder on a rock
0 The Spanish language tickles the ear baroque
1 If Europe wants Europe or its fate
Combination: 94.501.788.282.101
10 One's left with only sorrow and disease
5 Enough to spur on any picaro
6 It's finding out that's likely to displease
0 So stink the rotting skins from long ago
8 The Papuan sucks his friend's apophyses
0 The gauchos waving flags bravissimo
6 A brother even low is the proportion undecided
7 Most people like to read the words they know
6 Milord has lisped from Malibar to Swat
3 The shark is smoked on beds of bergamot
4 You can't quote Virgil in a limousine
8 We've all downed plonk from Calais to Bangkok
8 At meetings nibble nuts and watch the clock
1 If Europe wants Europe or its fate
Combination: 105.608.067.634.881
Further experimentation
By typing
python randomize_queneau.py | tr aeiou uoiae
you can get "gracious" outputs such as
1 King Curlas terns his caut far bottor foos
0 And sloovos uro wruppod raend harns af beffula
2 Tho chason freit is heod u bright coriso
2 All dering Lont ano freit's tho rutia
9 Yae got liko dirty gaads an besy qeuys
0 Tho guechas wuving flugs bruvissima
1 Tho flunks pratoctod by chovuex do friso
0 Ta puss tho timo wo stugo u littlo shaw
2 Tho inspirod paot isn't palyglat
4 At Chundrigur tho pousunt sniffs tho pat
5 Munero nat slesh bosmirchod his guburdino
1 Its fumaes scelpteros faendor an u rack
6 I qeito fargivo yae whon yae ren umak
2 Sa wo uro caesins naw ta king buloon
By typing
python randomize_queneau.py | tr aeiou uoiae
you can get "gracious" outputs such as
0 And sloovos uro wruppod raend harns af beffula
2 Tho chason freit is heod u bright coriso
2 All dering Lont ano freit's tho rutia
9 Yae got liko dirty gaads an besy qeuys
0 Tho guechas wuving flugs bruvissima
1 Tho flunks pratoctod by chovuex do friso
0 Ta puss tho timo wo stugo u littlo shaw
2 Tho inspirod paot isn't palyglat
4 At Chundrigur tho pousunt sniffs tho pat
5 Munero nat slesh bosmirchod his guburdino
1 Its fumaes scelpteros faendor an u rack
6 I qeito fargivo yae whon yae ren umak
2 Sa wo uro caesins naw ta king buloon
Resources
http://www.bevrowe.info/Queneau/
http://math.child.ru/otdohni/chitalka/TBO/Queneau.htm
http://www.growndodo.com/wordplay/oulipo/10%5e14sonnets.html
http://x42.com/active/queneau.html
http://www.decontextualize.com/teaching/rwet/functions-and-modules/
Printed version (in Spanish)
#python few constrains, endless permutations
Wednesday, February 13, 2013
Assignment # 1
Create a Python program that behaves like a UNIX text processing program (such as cat, grep, tr, etc.). Your program should take text as input (any text, or a particular text of your choosing) and output a version of the text that has been filtered and/or munged. Be creative, insightful, or intentionally banal.
Code
Original text (At the twilight | by Rumi)
At the twilight,
a moon
appeared in the sky.
Then it landed on earth to look at me.
Like a hawk
stealing a bird at the time of prey;
That moon stole me
and rushed back into the sky.
I looked at myself,
I did not see me anymore.
For in that moon,
my body
turned as fine as soul.
The nine spheres
disappeared in that moon;
The ship of my existence
drowned in that sea.
Result
At the soft glowing light from the region of the atmosphere and outer space seen from the earth when the sun is below the horizon, caused by the reflection of the sun's rays from the atmosphere,
a natural satellite of the the planet on which we live, visible by reflected light from the sun
appeared in the region of the atmosphere and outer space seen from the earth.
Then it landed on the planet on which we live to look at me.
Like a a diurnal warm-blooded egg-laying vertebrate with broad rounded wings and a long tail
stealing a warm-blooded egg-laying vertebrate at the time of prey;
That natural satellite of the the planet on which we live, visible by reflected light from the sun stole me
and rushed back into the region of the atmosphere and outer space seen from the earth.
I looked at myself,
I did not see me anymore.
For in that natural satellite of the the planet on which we live, visible by reflected light from the sun,
my physical structure, including the bones, flesh, and organs,
turned as fine as soul.
The nine spheres disappeared in that natural satellite of the the planet on which we live, visible by reflected light from the sun;
The ship of my state of living or having objective reality
drowned in that expanse of salt water that covers most of the earth's surface and surrounds its landmasses.
Wednesday, February 6, 2013
Grep
Grep is a command-line utility for searching plain-text data sets for lines matching a regular expression. Grep was originally developed for the Unix operating system, but is available today for all Unix-likesystems. Its name comes from the ed command g/re/p (global / regular expression / print). - Wikipedia
Exercise 0: Grepping Walt Whitman
1. Copy Whitman's work from Project Guttenberg and create a file called whitman.txt
2. Run Word Frecuency Counter Analysys.
3. Find the top 20 most frequent words:
10113 the
5334 and
4265 of
2906 i
2244 to
1875 in
1534 you
1293 a
1250 with
1109 is
1074 all
1014 my
1009 me
1003 or
993 for
877 not
854 that
816 as
792 it
703 from
671 on
4. Run the grep command using these words
grep the | grep and | grep of | grep to | grep in | grep you | grep with | grep is | grep all | grep my | grep me | grep or | grep for | grep not | grep that | grep as | grep it | grep from | grp on <whitman.txt | sort > whitmanhd5.txt
5. Display the first 26 lines (without any additional alterations):
Convict no more, nor shame, nor dole!
O fearful thought--a convict soul.
It is some dream that on the deck,
Where on the deck my Captain lies
With the life-long love of comrades.
A round full-orb'd eidolon.
A soul confined by bars and bands,
An image, an eidolon.
Beyond thy lectures learn'd professor,
But really build eidolons.
Dear prison'd soul bear up a space,
Do the feasters gluttonous feast?
Eidolons everlasting.
Eidolons! eidolons!
Eidolons, eidolons, eidolons.
Eidolons, eidolons.
Fill'd with eidolons only.
For soon or late the certain grace;
For the son is brought with the father,
God and eidolons.
I see a sad procession,
Immense and silent moon.
In its eidolon.
Issuing eidolons.
Joining eidolons.
Lo, the moon ascending.
Exercise 0: Grepping Walt Whitman
1. Copy Whitman's work from Project Guttenberg and create a file called whitman.txt
2. Run Word Frecuency Counter Analysys.
3. Find the top 20 most frequent words:
10113 the
5334 and
4265 of
2906 i
2244 to
1875 in
1534 you
1293 a
1250 with
1109 is
1074 all
1014 my
1009 me
1003 or
993 for
877 not
854 that
816 as
792 it
703 from
671 on
4. Run the grep command using these words
grep the | grep and | grep of | grep to | grep in | grep you | grep with | grep is | grep all | grep my | grep me | grep or | grep for | grep not | grep that | grep as | grep it | grep from | grp on <whitman.txt | sort > whitmanhd5.txt
5. Display the first 26 lines (without any additional alterations):
Convict no more, nor shame, nor dole!
O fearful thought--a convict soul.
It is some dream that on the deck,
Where on the deck my Captain lies
With the life-long love of comrades.
A round full-orb'd eidolon.
A soul confined by bars and bands,
An image, an eidolon.
Beyond thy lectures learn'd professor,
But really build eidolons.
Dear prison'd soul bear up a space,
Do the feasters gluttonous feast?
Eidolons everlasting.
Eidolons! eidolons!
Eidolons, eidolons, eidolons.
Eidolons, eidolons.
Fill'd with eidolons only.
For soon or late the certain grace;
For the son is brought with the father,
God and eidolons.
I see a sad procession,
Immense and silent moon.
In its eidolon.
Issuing eidolons.
Joining eidolons.
Lo, the moon ascending.
Subscribe to:
Posts (Atom)




























