equal
deleted
inserted
replaced
1 from lib import shorturl, db |
|
2 |
|
3 sdb = shorturl.DB() |
|
4 |
|
5 def gen () : |
|
6 count = 0 |
|
7 |
|
8 for key in sdb.db.keys() : |
|
9 if key.startswith("_") : |
|
10 continue |
|
11 |
|
12 print "%6s" % key, |
|
13 |
|
14 value = sdb.db[key] |
|
15 |
|
16 if not isinstance(value, tuple) or len(value) != 3 : |
|
17 print "CORRUPT VALUE!!!" |
|
18 continue |
|
19 |
|
20 type, dirpath, fname = value |
|
21 |
|
22 id = shorturl.key2int(key) |
|
23 dirpath = dirpath.lstrip('.').lstrip('/') |
|
24 |
|
25 if type == "img" : |
|
26 print "img" |
|
27 continue # already imported images |
|
28 |
|
29 print "img %6d %50s %10s" % (id, dirpath, fname) |
|
30 |
|
31 yield id, dirpath, fname |
|
32 |
|
33 else : |
|
34 |
|
35 print "dir %6d %50s" % (id, dirpath) |
|
36 |
|
37 yield id, dirpath, '' |
|
38 |
|
39 count += 1 |
|
40 |
|
41 if count % 500 == 0 : |
|
42 print count |
|
43 |
|
44 |
|
45 print "Starting import..." |
|
46 |
|
47 c = db.insert_many(""" |
|
48 INSERT OR IGNORE INTO nodes VALUES (?, ?, ?) |
|
49 """, gen()) |
|
50 |
|
51 print "Done!" |
|
52 |
|
53 print "%d rows affected" % c |
|