#!/usr/bin/env python import cgi, jinja2, os, json, re import cgitb; cgitb.enable() from jinja2 import Template # Directory => ITEMS list (all files with a timestamp name, grouped) ff = os.listdir("clips") tpat = re.compile(r"^(\d\d\d\d)-(\d\d)-(\d\d)-(\d\d)-(\d\d)-(\d\d)") items = {} for f in ff: base, ext = os.path.splitext(f) ext = ext[1:] m = tpat.match(f) if m: t = m.group(0) if t not in items: items[t] = {} items[t][ext] = f items = [items[key] for key in sorted(items, reverse=True)] for i in items[10:]: for f in i.items(): print "deleting ", f # 10 os.unlink(f) # dump the data (debugging) # print "Content-type: text/plain" # print "" # print json.dumps(items, indent=2) # Output template with items print "Content-type: text/html" print "" print Template(u""" ADOPT A WALK

Here you can find footage of your walks.

Steal a walk from another person's video. Download it.

Promise me, you're gonna start using this walk for the rest of the day.

{% for i in items %}

{{i.mp4}}

{% endfor %}
""").render(items=items).encode("utf-8")