#NEWLINE# def insert( self , thread ) : #NEWLINE# #INDENT# url = urlparse ( thread . find ( 'link' ) . text ) #NEWLINE# path = url . path #NEWLINE# if url . query : #NEWLINE# #INDENT# path += ( '?' + url . query ) #NEWLINE# #UNINDENT# self . db . threads . new ( path , thread . find ( 'title' ) . text . strip ( ) ) #NEWLINE# comments = list ( map ( self . Comment , thread . findall ( ( self . ns + 'comment' ) ) ) ) #NEWLINE# comments . sort ( key = ( lambda k : k [ 'id' ] ) ) #NEWLINE# remap = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ids = set ( ( c [ 'id' ] for c in comments ) ) #NEWLINE# self . count += len ( ids ) #NEWLINE# while comments : #NEWLINE# #INDENT# for ( i , item ) in enumerate ( comments ) : #NEWLINE# #INDENT# if ( item [ 'parent' ] in ids ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# item [ 'parent' ] = remap . get ( item [ 'parent' ] , None ) #NEWLINE# rv = self . db . comments . add ( path , item ) #NEWLINE# remap [ item [ 'id' ] ] = rv [ 'id' ] #NEWLINE# ids . remove ( item [ 'id' ] ) #NEWLINE# comments . pop ( i ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return