#!/usr/bin/python # surl - sort URLs by their last modification date import urllib import time import sys Date = {} while 1: # we only read from stdin not from argv. ln = sys.stdin.readline() if not ln: break ln = ln.strip() try: u = urllib.urlopen(ln) date = time.mktime(u.info().getdate("date")) if not Date.has_key(date): Date[date] = [] Date[date].append(ln) except: sys.stderr.write("%s: %s!\n" % (ln, sys.exc_info()[1])) dates = Date.keys() dates.sort() # python 2.4 would have sorted for d in dates: print "%s %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(d)), ", ".join(Date[d]))