Physics, Drupal and everything

Just some random blogging done via octopress

Use Desktop Notifications in the Shell

Many programs on linux provide notification integration, so for example if you resive a chat message you get a notification, so you don’t get disturbed too much, but at the other side also see what is going on.

If have relative long tasks, like compiling a big project with make, copying a lot of files or similar tasks you sometimes just want to have a notification for that as well.

One solution on on linux is to use the package “notify-cli” which provides you notify-send.

It’s pretty damn simple to use

1
notify-send "Title" "Longer text"

In combination with make you can for example use

1
make && notify-send "make" "make is ready for pyopencl"

Link: Proper Python String Formatting]

On http://mkaz.com/solog/python-string-format you find a really great overview of all different kind of string formatting options in python, also numbers etc.

This is one of the parts of the official docu, which kind of lacks behind.

Dowload Full Lectures on Timms

The university of tuebingen allows you to watch a limited amount of lectures on a multimedia server called “timms”, see http://timms.uni-tuebingen.de

As every topic is splitted into lectures it’s quite annoying to download/look all of them, so let’s write a script that downloads them all.

This small blog entry describes the process of how to solve such a problem.

First steps

The first steps has been to look at the actual urls, here are the ones from the first two.

1
http://timms.uni-tuebingen.de/Player/AccessASF.aspx?ref=mms%3a%2f%2fu-003-stimms03.uni-tuebingen.de%2fUT_2006%2f10%2f18%2fUT_20061018_001_exphys7_0001.wmv500.wmv&starttime=0.0&title=Vorlesung+Experimentalphysik+VII%2c+1.+Stunde©right=%c2%a92006+Universit%c3%a4t+T%c3%bcbingen%2c+duplication+and+capturing+prohibited

As you see pretty much nothing is important beside the string after ?ref=, so let’s unescape it:

1
2
3
4
5
6
7
import urllib

urllib.unquote("mms%3a%2f%2fu-003-stimms03.uni-tuebingen.de%2fUT_2006%2f10%2f18%2fUT_20061018_001_exphys7_0001.wmv500.wmv")

> mms://u-003-stimms03.uni-tuebingen.de/UT_2006/10/18/UT_20061018_001_exphys7_0001.wmv500.wmv
> mms://u-003-stimms03.uni-tuebingen.de/UT_2006/10/18/UT_20061018_002_exphys7_0001.wmv500.wmv
> mms://u-003-stimms03.uni-tuebingen.de/UT_2006/10/19/UT_20061019_001_exphys7_0001.wmv500.wmv

The schema so of the urls are pretty clear: servername/some semester/month/day/bla$piece$name.wmv500.wmv.

Find all the download urls

In order to find all this different links, let’s go to the overview page and start to parse it with pyquery.

1
2
3
4
from pyquery import PyQuery as pq

# Download the timms overview page.
py = pq(url="http://timms.uni-tuebingen.de/List/List01.aspx?rpattern=UT_200[67]_____00[12]_exphys7_000_")

As you will see there are images with the following schema on the page: “jtimms/images/UT_2006/10/18/UT_20061018_001_…” with the needed urls, pretty useful.

Now the only thing left is to get all the links and run an mplayer dump command on it, and

1
2
3
4
5
6
7
8
urls = []
# The goal is to find all urls needed to download, but they are part of the images.
for image in py.find("table#content").find("img"):
    src = image.attrib['src']
    if src.find("jtimms") != -1:
        url_part = src.replace("/jtimms/images/", "").replace(".prev.jpg", "")
        url = "mms://u-003-stimms03.uni-tuebingen.de/{}.wmv500.wmv".format(url_part)
        urls.append(url)

Catch them all

The final step is to dump them all into video files, this example uses mplayer for that.

1
2
3
4
5
6
7
8
9
10
import os
import subprocess

# We scanned the site from top to the bottom.
urls.reverse()

counter = 0
for url in urls:
    counter = counter + 1
    subprocess.Popen(['mplayer', '-dumpstream', '-dumpfile', "video-{}.wmv".format(counter), url])

The final notebook can be found under a gist

Initial Post

Just a python test
1
2
3
import numpy as np

print np.random.rand(10)