Skip to content

Instantly share code, notes, and snippets.

@eigilhs
Created March 4, 2013 14:45
Embed
What would you like to do?
Script for å vise Dilbert-striper
#!/usr/bin/env python
import os, re, sys, urllib, random, datetime, time
root = "http://www.dilbert.com/"
address = root + "fast/" # today's strip
if len(sys.argv) == 2 and sys.argv[-1] != "-r": # specified strip
date = re.findall("\d\d\d\d\-\d\d\-\d\d", sys.argv[1].strip())
if date: address += date[0] + "/"
else: sys.exit("Illegal date: " + sys.argv[1] + "\nUse format YYYY-MM-DD.")
elif sys.argv[-1] == "-r": # random strip
current = time.time()
beginning = 608680800.0 # 1989-04-16
random_date = random.random() * (current - beginning)
address += str(datetime.date.fromtimestamp(beginning + random_date)) + "/"
for line in urllib.urlopen(address):
m = re.findall("dyn/str_strip/.*\.strip", line)
if m: break
image = root + m[0] + ".zoom.gif"
os.system("curl -s " + image + " | display &")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment