Snippet: A sed shell in Python
Here is a very simple shell in Python to test regular expressions with sed.
The shell works by matching the input as a sed command against a given data.
Each input line is evaluated as a Python expression (and it must evaluate to a [base]string) and then sent to sed as a command to be matched against this given data.
So every input is the same as:
echo <data> | sed -r -e <input>
<data> is set by using the d() function:
>> d("My data")
>> r's#^My#Our#'
Our data
To see what <data> contains, simply use the d() function without arguments:
>> d()
My data
(<data> defaults to the alphabet string "abc...z")
To exit, use Ctrl-C (KeyboardInterrupt) or send an EOF to it (Windows: Ctrl-Z+Enter, Linux: Ctrl-D) or yet use the exit() function.
Snippet: Reading a playlist from YouTube with Python
I play some games, often those of the kind: easy to learn, hard to master (and I've played serious sometimes, but not nowadays). Recently I've been playing the great Race Driver: GRID. (Which is really hard to master with only a keyboard, probably impossible.)
In this game you can race the prestigious 24 Hours of Le Mans, a endurance race of 24 hours that has 4 classes, many teams per class, each class has 3 drivers (yes, of course, they switch drivers to reach the 24h mark).
All right, what a Python code snippet has to do with all this? Nothing much, actually (I just got very excited about the whole Le Mans thing), but the thing is that I went searching for videos on YouTube about Le Mans and found some real nice videos in a specific playlist. I wanted to extract all the links from that playlist, for further use later, and then ended writing the simple script below.
It will grab the links from the Google Data API, using the playlist id. The details are inside the script comments.
Besides the code, which is really simple and short, the whole post's point is that I love this excitement feeling when you get interested in something then goes and writes some code, hopefully useful. This gives me the stamina to write even more (plus commenting it), stop to write down a blog post (and actually searching for images, editing, etc), so all this even could result in a little project. Not this subject, the playlist reader, but could be anything.

