From 07947b1411a41fc2af53d382b2ce79af75b89f12 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 11 Apr 2011 14:02:16 +0200 Subject: [PATCH] Add script to generate the short URLs on the commandline, for old posts --- shorturl.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 shorturl.py diff --git a/shorturl.py b/shorturl.py new file mode 100755 index 0000000..8b02947 --- /dev/null +++ b/shorturl.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import sys + +# Simple map used to shorten id values to URLs +_urlvalmap = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '_'] + +def shortid(id): + s = "" + while id > 0: + s = _urlvalmap[id % 64] + s + id /= 64 + return "http://postgr.es/p/%s" % s + + +if len(sys.argv) != 2: + print "Usage: shorturl.py " + sys.exit(1) + +id = int(sys.argv[1]) + +print "%s -> %s" % (id, shortid(id)) -- 2.39.5