Twenty things to do with a python script

From XPUB & Lens-Based wiki
Revision as of 22:04, 21 November 2013 by Michael Murtaugh (talk | contribs)

With a deferential bow to Seymour Papert & Cynthia Solomon's 1971 20 Things to do with a computer, here a selected listing of Python recipes that represent a range posible explorations that need not involve much more than 20 - 30 lines of code.

Construction.gif Code/links/images to be added

<slidy theme="aa />

Make a turtle

import turtle

TODO: include classic turtle graphics example + text about Papert, et al

Create an Inkscape plugin to draw turtle graphics

See Seymour

Generating tactical text hybrids

“Emma Woodhouse, handsome, clever, and create derivative works of. 9. We can analyze your application. We can remove any ad for any purpose, including Connect sites. * Payment Terms: These guidelines outline the policies that apply to users. 5. If any portion of this Statement must be the difference between a Mrs. Weston, only sixteen miles off, was always disagreeable”

Using nltk

Source: Femke Snelting, http://snelting.domainepublic.net/files/EmmaWoodhouse.odt

Programmatically Manipulating Typefaces

EricSchrijverProgrammaticallyManipulatingTypfaces.png

Using fontforge and robofab

Source: Eric Schrijver, http://i.liketightpants.net/and/programmatically-manipulating-typefaces

Spidering texts and extracting strategic search patterns

ective enforcement of intellectual property rights is critical to sustaining e
or the enforcement of intellectual property rights , taking into account diffe
procedures to enforce intellectual property rights do not themselves become ba
em of infringement of intellectual property rights , including infringement ta
ensive enforcement of intellectual property rights than is required by this Ag
etween enforcement of intellectual property rights and enforcement of law in g
lability and Scope of Intellectual property Rights 1 . This Agreement shall be
 , and maintenance of intellectual property rights . 2 . This Agreement does n
ures where a right in intellectual property is not protected under its laws an
rk for Enforcement of Intellectual property Rights ) are invoked ; ACTA / en 7
calendar days ; ( h ) intellectual property refers to all categories of intell
 to all categories of intellectual property that are the subject of Sections 1
rk for Enforcement of Intellectual property Rights ) are invoked ; ACTA / en 8
g to assert rights in intellectual property ; ( m ) territory , for the purpos
rk for Enforcement of Intellectual property Rights ), means the customs territ
 - Related Aspects of Intellectual property Rights , contained in Annex 1C to 
RK FOR ENFORCEMENT OF INTELLECTUAL property RIGHTS SECTION 1 GENERAL OBLIGATIO
ct of infringement of intellectual property rights covered by this Agreement ,
he enforcement of any intellectual property right as specified in this Section
ng the enforcement of intellectual property rights , its judicial authorities 
he infringement of an intellectual property right from entering into the chann
ng the enforcement of intellectual property rights , its judicial authorities 
s for infringement of intellectual property rights , a Party ' s judicial auth
 the right holder ' s intellectual property right in question and actually ass
horization to use the intellectual property right in question . ACTA / en 14 A

Source: Nicolas Malevé, http://vj13.constantvzw.org/live/deskcam/

Run a web server

python -m SimpleHTTPServer

Permute the spellings of search terms

Source: Linda Hilfling, the experiments were developed later into the Misspelling generator browser plugin & project

Create a detourned search engine

http://pzwart3.wdka.hro.nl/~sschmieg/cgi-bin/g+7/index.py

Source: Sebastian Schmieg with Silvio Lorusso

Create a Traceroute Map

Source: User:Roelroscama/trim1/protoyping

Scrape Albert Heijn Loyalty Cards

http://vimeo.com/50859298

Source: Birgit Bachler, http://www.birgitbachler.com/portfolio/?p=506

Create a custom joystick sound recorder

Uses: pygame

RugzakPeterWestenberg.jpg

Source: Peter Westenberg, http://www.deschaarbeeksetaal.be/p/rugzak/

Slice & reorder an audio file by predominant frequency (NM/MM)

http://kurenniemi.activearchives.org/spectrum/

Create clouds of 3D objects in Blender

https://github.com/Blender-Brussels/bpy-bge-library/blob/master/scripts/bpy/duplicate_object.py

Source: Julien Deswaef, Brussels Blender Group []

Create a dotcom index using letter permuations

http://www.roelroscamabbing.nl/dotcomindex.html

Source: User:Roelroscama, prototyping

Filter a subtitle file to highlight the unique words of a spoken text (Disappearance)

http://activearchives.org/wiki/Disappearance

Source: Alexandre Leray and Stéphanie_Vilayphiou

Generate an epub

Create generative fugues

Scetchbook2011-02 markov.jpg

Voice 01 (Octave 2) File:Fugue 01 20110608.ogg
Voice 02 (Octave 3) File:Fugue 04 20110530.ogg
Voice 03 (Octave 4) File:Fugue 01-octave4 20110608.ogg

Source: Natasa Siencnik User:Natasa_Siencnik/prototyping/markov

Use open clip art and a loop to make a book of patterns

Amanofmanyparts.gif

Uses: SVG, Inkscape

 
print """<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
    "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"
	 width="200px" height="50px"
	 viewBox="0 0 200 50"
	 zoomAndPan="disable" >"""

# vertical amount of elements
veramo = 20

# ydist increases the vertical distance
ydist = 10

for z in range(veramo):
    transf = "transform=\"translate({0},{1})\">".format(0,z*ydist)
    print "<g " + transf
    # horizontal amount of elements
    horamo = 20
    # ydist2 increases the vertical distance
    ydist2 = 10
    # xdist increases the horizontal distance
    xdist2 = 10
    for x in range(horamo):
        transf = "transform=\"translate({0},{1})\"".format(x*xdist,x*ydist2) 
        print "<rect " + transf + """ x="0" y="0" width="10" height="10" fill="black" />
    print "</g>"

print "</svg>"

Source: Silvio Lorusso, User:Silviolorusso/Amanofmanyparts

Generating Outline Fonts with 5 Lines of Code

Douar-outline-1024x640.png

import fontforge
font = fontforge.open('douar.sfd')
for glyph in font:
    font[glyph].stroke('circular',  30, 'square', 'bevel', ('cleanup',))
font.generate('douar-new.ttf')

Uses: FontForge

Source: Ricardo Lafuente, http://blog.manufacturaindependente.org/2011/02/generating-outline-fonts-with-5-lines-of-code/

Create interactive vector graphics

http://www.stuartaxon.com/2013/03/20/natural-movement-in-python-part-3-particles/#more-331

Uses: Shoebot (http://shoebot.net/)

Source: Stuart Axon and Ricardo Lafuente

other

  • Manipulate images with PIL?
  • reportlab to generate a paginated PDF
  • subprocess (Run a shell command & process it's output (using FFMPEG to get audio/video info))
  • html5lib: simple scrape starting code
  • glob
  • urllib, urlparse, ...
  • json
  • optparse
  • random
  • datetime
  • SimpleHTTPServer
  • SocketServer / OSC
  • turtle
  • uuid
  • zipfile
  • xml (Read and extract data from an XML file)