#NEWLINE# def worldleaders_parse( emit , json_file ) : #NEWLINE# #INDENT# with open ( data , 'r' ) as fh : #NEWLINE# #INDENT# data = json . load ( fh ) #NEWLINE# #UNINDENT# for leader in data . get ( 'leaders' ) : #NEWLINE# #INDENT# if ( not len ( leader . get ( 'name' ) ) ) : #NEWLINE# #INDENT# log . warning ( 'No name on entity: %(title)s (%(country)s)' , leader ) #NEWLINE# continue #NEWLINE# #UNINDENT# country = normalize_country ( leader . get ( 'country' ) ) #NEWLINE# summary = leader . get ( 'title' ) #NEWLINE# if leader . get ( 'component' ) : #NEWLINE# #INDENT# summary = ( '%s (%s)' % ( summary , leader . get ( 'component' ) ) ) #NEWLINE# #UNINDENT# entity = { #NEWLINE# #INDENT# 'uid' : make_id ( 'us' , 'cia' , 'worldleaders' , country , leader . get ( 'name' ) ) , #NEWLINE# 'name' : leader . get ( 'name' ) , #NEWLINE# 'type' : 'individual' , #NEWLINE# 'summary' : summary , #NEWLINE# 'addresses' : [ { #NEWLINE# #INDENT# 'country' : country , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'updated_at' : parse_date ( leader . get ( 'last_update' ) ) , #NEWLINE# 'source_url' : leader . get ( 'url' ) , #NEWLINE# #UNINDENT# } #NEWLINE# entity . update ( PUBLISHER ) #NEWLINE# emit . entity ( entity )