diff -r b75f9514e797 -r 72696ca68c34 scripts/migrate_shorturls.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/migrate_shorturls.py Wed Jan 16 18:44:03 2008 +0000 @@ -0,0 +1,51 @@ +from lib import shorturl, db + +sdb = shorturl.DB() + +def gen () : + count = 0 + + for key in sdb.db.keys() : + if key.startswith("_") : + continue + + print "%6s" % key, + + value = sdb.db[key] + + if not isinstance(value, tuple) or len(value) != 3 : + print "CORRUPT VALUE!!!" + continue + + type, dirpath, fname = value + + if type == "img" : + id = shorturl.key2int(key) + + dirpath = dirpath.lstrip('.').lstrip('/') + + print "%6d %50s %10s" % (id, dirpath, fname) + + yield id, dirpath, fname + + count += 1 + + if count % 500 == 0 : + print count + else : + print "dir" + +print "Starting import..." + +c = db.cursor() + +c.executemany(""" + INSERT INTO images VALUES (?, ?, ?) +""", gen()) + +print "Done!" + +print "%d rows affected" % c.rowcount + +c.execute("SELECT id FROM images").fetchall() +