scripts/migrate_shorturls.py
changeset 26 81d6679d50d0
parent 22 72696ca68c34
child 31 09776792a91c
equal deleted inserted replaced
25:4b3cf12848c2 26:81d6679d50d0
    17             print "CORRUPT VALUE!!!"
    17             print "CORRUPT VALUE!!!"
    18             continue
    18             continue
    19 
    19 
    20         type, dirpath, fname = value
    20         type, dirpath, fname = value
    21 
    21 
       
    22         id = shorturl.key2int(key)
       
    23         dirpath = dirpath.lstrip('.').lstrip('/')
       
    24 
    22         if type == "img" :
    25         if type == "img" :
    23             id = shorturl.key2int(key)
    26             print "img"
       
    27             continue    # already imported images
    24 
    28 
    25             dirpath = dirpath.lstrip('.').lstrip('/')
    29             print "img %6d %50s %10s" % (id, dirpath, fname)
    26 
       
    27             print "%6d %50s %10s" % (id, dirpath, fname)
       
    28 
    30 
    29             yield id, dirpath, fname
    31             yield id, dirpath, fname
    30 
    32 
    31             count += 1
    33         else :
    32 
    34 
    33             if count % 500 == 0 :
    35             print "dir %6d %50s" % (id, dirpath)
    34                 print count
    36 
    35         else :
    37             yield id, dirpath, ''
    36             print "dir"
    38 
       
    39         count += 1
       
    40 
       
    41         if count % 500 == 0 :
       
    42             print count
       
    43 
    37 
    44 
    38 print "Starting import..."
    45 print "Starting import..."
    39 
    46 
    40 c = db.cursor()
    47 c = db.insert_many("""
    41 
    48     INSERT OR IGNORE INTO nodes VALUES (?, ?, ?)
    42 c.executemany("""
       
    43     INSERT INTO images VALUES (?, ?, ?)
       
    44 """, gen())
    49 """, gen())
    45 
    50 
    46 print "Done!"
    51 print "Done!"
    47 
    52 
    48 print "%d rows affected" % c.rowcount
    53 print "%d rows affected" % c
    49 
    54 
    50 c.execute("SELECT id FROM images").fetchall()
       
    51