#NEWLINE# def migrate( self ) : #NEWLINE# #INDENT# tree = ElementTree . parse ( self . xmlfile ) #NEWLINE# res = defaultdict ( list ) #NEWLINE# for post in tree . findall ( ( Disqus . ns + 'post' ) ) : #NEWLINE# #INDENT# item = { #NEWLINE# #INDENT# 'dsq:id' : post . attrib . get ( ( Disqus . internals + 'id' ) ) , #NEWLINE# 'text' : post . find ( ( Disqus . ns + 'message' ) ) . text , #NEWLINE# 'author' : post . find ( '{0}author/{0}name' . format ( Disqus . ns ) ) . text , #NEWLINE# 'email' : post . find ( '{0}author/{0}email' . format ( Disqus . ns ) ) . text , #NEWLINE# 'created' : mktime ( strptime ( post . find ( ( Disqus . ns + 'createdAt' ) ) . text , '%Y-%m-%dT%H:%M:%SZ' ) ) , #NEWLINE# 'remote_addr' : anonymize ( post . find ( ( Disqus . ns + 'ipAddress' ) ) . text ) , #NEWLINE# 'mode' : ( 1 if ( post . find ( ( Disqus . ns + 'isDeleted' ) ) . text == 'false' ) else 4 ) , #NEWLINE# #UNINDENT# } #NEWLINE# if ( post . find ( ( Disqus . ns + 'parent' ) ) is not None ) : #NEWLINE# #INDENT# item [ 'dsq:parent' ] = post . find ( ( Disqus . ns + 'parent' ) ) . attrib . get ( ( Disqus . internals + 'id' ) ) #NEWLINE# #UNINDENT# res [ post . find ( ( '%sthread' % Disqus . ns ) ) . attrib . get ( ( Disqus . internals + 'id' ) ) ] . append ( item ) #NEWLINE# #UNINDENT# progress = Progress ( len ( tree . findall ( ( Disqus . ns + 'thread' ) ) ) ) #NEWLINE# for ( i , thread ) in enumerate ( tree . findall ( ( Disqus . ns + 'thread' ) ) ) : #NEWLINE# #INDENT# progress . update ( i , thread . find ( ( Disqus . ns + 'id' ) ) . text ) #NEWLINE# if ( ( thread . find ( ( Disqus . ns + 'id' ) ) . text is None ) and ( not self . empty_id ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# id = thread . attrib . get ( ( Disqus . internals + 'id' ) ) #NEWLINE# if ( id in res ) : #NEWLINE# #INDENT# self . threads . add ( id ) #NEWLINE# self . insert ( thread , res [ id ] ) #NEWLINE# #UNINDENT# #UNINDENT# self . db . comments . _remove_stale ( ) #NEWLINE# progress . finish ( '{0} threads, {1} comments' . format ( len ( self . threads ) , len ( self . comments ) ) ) #NEWLINE# orphans = ( set ( map ( ( lambda e : e . attrib . get ( ( Disqus . internals + 'id' ) ) ) , tree . findall ( ( Disqus . ns + 'post' ) ) ) ) - self . comments ) #NEWLINE# if ( orphans and ( not self . threads ) ) : #NEWLINE# #INDENT# print ( "Isso couldn't import any thread, try again with --empty-id" ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if orphans : #NEWLINE# #INDENT# print ( ( 'Found %i orphans:' % len ( orphans ) ) ) #NEWLINE# for post in tree . findall ( ( Disqus . ns + 'post' ) ) : #NEWLINE# #INDENT# if ( post . attrib . get ( ( Disqus . internals + 'id' ) ) not in orphans ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# print ( ' * {0} by {1} <{2}>' . format ( post . attrib . get ( ( Disqus . internals + 'id' ) ) , post . find ( '{0}author/{0}name' . format ( Disqus . ns ) ) . text , post . find ( '{0}author/{0}email' . format ( Disqus . ns ) ) . text ) ) #NEWLINE# print ( textwrap . fill ( post . find ( ( Disqus . ns + 'message' ) ) . text , initial_indent = '  ' , subsequent_indent = '  ' ) ) #NEWLINE# print ( '' )