Disqus import uses Progressbar class as well
This commit is contained in:
parent
12f8af8434
commit
39101c2ac7
@ -93,7 +93,7 @@ class Disqus(object):
|
|||||||
tree = ElementTree.parse(self.xmlfile)
|
tree = ElementTree.parse(self.xmlfile)
|
||||||
res = defaultdict(list)
|
res = defaultdict(list)
|
||||||
|
|
||||||
for post in tree.findall('%spost' % Disqus.ns):
|
for post in tree.findall(Disqus.ns + 'post'):
|
||||||
|
|
||||||
item = {
|
item = {
|
||||||
'dsq:id': post.attrib.get(Disqus.internals + 'id'),
|
'dsq:id': post.attrib.get(Disqus.internals + 'id'),
|
||||||
@ -111,15 +111,9 @@ class Disqus(object):
|
|||||||
|
|
||||||
res[post.find('%sthread' % Disqus.ns).attrib.get(Disqus.internals + 'id')].append(item)
|
res[post.find('%sthread' % Disqus.ns).attrib.get(Disqus.internals + 'id')].append(item)
|
||||||
|
|
||||||
num = len(tree.findall(Disqus.ns + 'thread'))
|
progress = Progress(len(tree.findall(Disqus.ns + 'thread')))
|
||||||
cols = int((os.popen('stty size', 'r').read() or "25 80").split()[1])
|
|
||||||
|
|
||||||
for i, thread in enumerate(tree.findall(Disqus.ns + 'thread')):
|
for i, thread in enumerate(tree.findall(Disqus.ns + 'thread')):
|
||||||
|
progress.update(i, thread.find(Disqus.ns + 'id').text)
|
||||||
if int(round((i+1)/num, 2) * 100) % 13 == 0:
|
|
||||||
sys.stdout.write("\r%s" % (" "*cols))
|
|
||||||
sys.stdout.write("\r[%i%%] %s" % (((i+1)/num * 100), thread.find(Disqus.ns + 'id').text))
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
# skip (possibly?) duplicate, but empty thread elements
|
# skip (possibly?) duplicate, but empty thread elements
|
||||||
if thread.find(Disqus.ns + 'id').text is None:
|
if thread.find(Disqus.ns + 'id').text is None:
|
||||||
@ -133,8 +127,7 @@ class Disqus(object):
|
|||||||
# in case a comment has been deleted (and no further childs)
|
# in case a comment has been deleted (and no further childs)
|
||||||
self.db.comments._remove_stale()
|
self.db.comments._remove_stale()
|
||||||
|
|
||||||
sys.stdout.write("\r%s" % (" "*cols))
|
progress.finish("{0} threads, {1} comments".format(
|
||||||
sys.stdout.write("\r[100%] {0} threads, {1} comments\n".format(
|
|
||||||
len(self.threads), len(self.comments)))
|
len(self.threads), len(self.comments)))
|
||||||
|
|
||||||
orphans = set(map(lambda e: e.attrib.get(Disqus.internals + "id"), tree.findall(Disqus.ns + "post"))) - self.comments
|
orphans = set(map(lambda e: e.attrib.get(Disqus.internals + "id"), tree.findall(Disqus.ns + "post"))) - self.comments
|
||||||
|
@ -24,6 +24,8 @@ class TestMigration(unittest.TestCase):
|
|||||||
db = SQLite3(xxx.name, Config.load(None))
|
db = SQLite3(xxx.name, Config.load(None))
|
||||||
Disqus(db, xml).migrate()
|
Disqus(db, xml).migrate()
|
||||||
|
|
||||||
|
self.assertEqual(len(db.execute("SELECT id FROM comments").fetchall()), 2)
|
||||||
|
|
||||||
self.assertEqual(db.threads["/"]["title"], "Hello, World!")
|
self.assertEqual(db.threads["/"]["title"], "Hello, World!")
|
||||||
self.assertEqual(db.threads["/"]["id"], 1)
|
self.assertEqual(db.threads["/"]["id"], 1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user