User:Selena Savic/Techdaze

From XPUB & Lens-Based wiki
< User:Selena Savic
Revision as of 20:38, 23 September 2010 by Migratebot (talk | contribs) (Created page with " == second assignement == === Totally Wasted === took the [http://www.gutenberg.org/etext/29888 "Hunting of the Snark"] by Lewis Carrol; read it in and split it into ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


second assignement

Totally Wasted

took the "Hunting of the Snark" by Lewis Carrol;

read it in and split it into a list;

found words ending with ly and ed, zipped them into one list and printed the couples;

didn't get rid of _-+&{}'\/'......

import re

tekst = open("hunting-snark.txt").read().split()

#print tekst

ly = []

ed = []

for word in tekst:
#   re.sub(r"\s[+_-]", "", tekst)
    if word.endswith("ly"):
        ly.append(word)
    elif word.endswith("ed"):
        ed.append(word)

#print ly
#print ed

zipped = zip(ly, ed)
#print zipped

for a, b in zipped:
    print a, b


produces pairs like this:

generously included
indignantly proceed
cautiously printed
only inculcated
hardly sailed
wholly connected
unaccountably landed
frequently saved
lovingly famed
frequently entered
deeply painted
exactly frightened
suddenly pleased
generously wasted
electronically unfrequented
indirectly tried
only uttered
....

Web Comics

a web comic with only images from a web page

Images taken from the google image search on "guantanamo" and "pink";

Write a python script like this and save it under webcomics.py:

import urllib2, urlparse, os, sys
import html5lib

def openURL (url):
    """
    returns (page, actualurl)
    sets user_agent and resolves possible redirection
    realurl maybe different than url in the case of a redirect
    """    
    request = urllib2.Request(url)
    user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5"
    request.add_header("User-Agent", user_agent)
    pagefile=urllib2.urlopen(request)
    realurl = pagefile.geturl()
    return (pagefile, realurl)

(f,url)= openURL ("http://images.google.nl/images?source=ig&hl=nl&rlz=&=&q=guantanmo+pink&lr=&oq=&um=1&ie=UTF-8&sa=N&tab=wi")

print "Content-type: text/html; charset=utf8"
print

print "<html><head><title>webcomic one</title></head><body>"

parser = html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("dom"))

tree = parser.parse(f)

f.close()
tree.normalize()

for node in tree.getElementsByTagName("img"):
    src = node.getAttribute("src")
    print "<img src='" + src + "' height=150px border=4px>"

sys.exit()

print """
</body>
</html> 
"""


then run:

python webcomics.py > webcomics.html


then open it with firefox to see the results

firefox webcomics.html


a web comic made of a mix of two sources of images

import urllib2, urlparse, os, sys
import html5lib


def openURL (url):
    """
    returns (page, actualurl)
    sets user_agent and resolves possible redirection
    realurl maybe different than url in the case of a redirect
    """
    request = urllib2.Request(url)
    user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5"
    request.add_header("User-Agent", user_agent)
    pagefile=urllib2.urlopen(request)
    realurl = pagefile.geturl()
    return (pagefile, realurl)

(f,url)= openURL ("http://images.google.nl/images?source=ig&hl=nl&rlz=&=&q=guantanamo+pink&lr=&oq=&um=1&ie=UTF-8&sa=N&tab=wi") #first source: google image search for guantanamo + pink

(g,url)= openURL ("http://images.google.nl/images?source=ig&hl=nl&rlz=&=&q=bay+white&lr=&oq=&um=1&ie=UTF-8&sa=N&tab=wi") #second source: google image search for bay + white

print "Content-type: text/html; charset=utf8"
print
 
  
print "<html><head><title>webcomic two</title>"
print "<style type='text/css'> .imgs {height:140px; border-style:solid; border-color: black; border-width:4px; margin: 4px;} </style>"
print "</head><body>"

parser = html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("dom"))

treef = parser.parse(f) #create a dom tree from the search results of the 'f' search
treeg = parser.parse(g) #create a dom tree from the search results of the 'g' search

f.close()
g.close() 

treef.normalize()
treeg.normalize()

##create empty lists to be filled in with images from the two sources
flist = [] 
glist = []

##appends all the images from the 'f' tree to the list
for node in treef.getElementsByTagName("img"):
    src = node.getAttribute("src")
    flist.append(src)

##appends all the images from the 'g' tree to the list
for node in treeg.getElementsByTagName("img"):
    src = node.getAttribute("src")
    glist.append(src)

#print flist
#print glist

##adds the two lists together, making a list of pairs of elements from both lists in tuples 
zipped = zip(flist, glist)
#print zipped

for fimg, gimg in zipped:
    print "<img src='" + fimg + "' class='imgs'>" + "<img src='" + gimg + "' class='imgs'>"

sys.exit()

print """
</body>
</html> 
"""


Palindrome Headlines

Palindrome the title of a feed:

feed used > Gmail - Inbox for idealnigrad@gmail.com : New messages in your Gmail Inbox

 
import feedparser

mails = feedparser.parse("https://USERNAME:PASSWORD@gmail.google.com/gmail/feed/atom")

for entry in mails.entries:
    words = entry.title.split()
#   n = len(words) -2
#   palindrome = words + words[n::-1]
    palindrome = words+ words[::-1][1:]
    print " ".join(palindrome)


finally:

How to embed a video in the wiki page

Aymeric has enabled embedding of flash videos on the wiki!

Movie(wiki:People SelenaSavic Techdaze movie.flv)

command line movie

i used two youtube videos:
Rapist Glasses
and
Pedophile Beards
to test a disturbing effect of the 25th frame. I found it too short and flashing and decided to reduce the frame rate to 12fps.

User Selena Savic Techdaze rapist.jpg


User Selena Savic Techdaze pedophile.jpg


the script to rename the files:
numbers growing in the steps of 1

import os

os.system("mkdir renamed")
n = 0
i = 1
#started = False

while n<1000:
    f = "rapist%04d.jpeg" % n
    if os.path.isfile(f):
        new_file = "renamed/%04d.jpg" % i
        i += 1
        os.system("cp %s %s" % (f, new_file))
    n += 1

numbers growing in the steps of 25

import os

os.system("mkdir renamed25")
n = 0
i = 1
#started = False

while n<1000:
    f = "pedo%04d.jpeg" % n
    if os.path.isfile(f):
        new_file = "renamed25/%04d.jpg" % i
        i += 25
        os.system("cp %s %s" % (f, new_file))
    n += 1


The audio is made with a speech generator - festival, randomly speaking out words "rapist", "pedophile" and "public masturbator" with a python script:

from os import system
import random

system("echo 'pedophile' | text2wave -scale 10 -o pedophile.raw")
system("echo 'rapist' | text2wave -scale 10 -o rapist.raw")
system("echo 'public masturbator' | text2wave -scale 10 -o masturbator.raw")

for i in range(10):
    word = random.choice('123')
    if word == '1':
        system("play pedophile.raw")
        system("cat pedophile.raw > sound.raw")
    if word == '2':
        system("play masturbator.raw")
        system("cat masturbator.raw > sound.raw")
    else:
        system("play rapist.raw")
        system("cat rapist.raw > sound.raw")


Here, finally, the movie!

movie.avi

sound loops

two "songs" generated in python using sox: here

anima

at the polly pocket museum

User Selena Savic Techdaze polly.gif


here is the script:

#!/bin/bash                                                                     
                                                                                
mkdir anima                                                                     
cd anima                                                                        
wget http://pp-moma.com/pictures/pic/pony.ppmoma.pony.ul.450.450.90.jpg         
mv pony.ppmoma.pony.ul.450.450.90.jpg polly000.jpg                              
mogrify -resize 400 polly000.jpg                                                
convert polly000.jpg -sigmoidal-contrast 2,0% polly001.jpg                      
convert polly000.jpg -sigmoidal-contrast 8,0% polly002.jpg                      
convert polly000.jpg -sigmoidal-contrast 20,0% polly003.jpg                     
convert polly000.jpg -sigmoidal-contrast 1,0% polly004.jpg                      
convert polly000.jpg -sigmoidal-contrast 2,0% polly005.jpg                      
convert polly000.jpg -sigmoidal-contrast 7,0% polly006.jpg                      
convert polly000.jpg -sigmoidal-contrast 17,0% polly007.jpg                     
convert polly000.jpg -sigmoidal-contrast 3,0% polly008.jpg                      
convert polly000.jpg -sigmoidal-contrast 1,0% polly009.jpg                      
convert polly000.jpg -sigmoidal-contrast 2,0% polly010.jpg                      
convert polly000.jpg -sigmoidal-contrast 4,0% polly011.jpg                      
convert polly000.jpg -sigmoidal-contrast 12,0% polly012.jpg                     
convert polly000.jpg -sigmoidal-contrast 18,0% polly013.jpg                     
convert polly* polly.gif


Attachments