#NEWLINE# def load( self ) : #NEWLINE# #INDENT# self . _common_kwargs = self . _build_common_election_kwargs ( ) #NEWLINE# self . _common_kwargs [ 'reporting_level' ] = 'county' #NEWLINE# results = [ ] #NEWLINE# with self . _file_handle as csvfile : #NEWLINE# #INDENT# district_flag = 0 #NEWLINE# reader = unicodecsv . DictReader ( csvfile , encoding = 'latin-1' , delimiter = ',' ) #NEWLINE# self . header = [ x . replace ( '"' , '' ) for x in reader . fieldnames ] #NEWLINE# self . contest_index = normalize_contest ( self . header ) #NEWLINE# for row in reader : #NEWLINE# #INDENT# if self . _skip_row ( row ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rr_kwargs = self . _common_kwargs . copy ( ) #NEWLINE# rr_kwargs [ 'primary_party' ] = row [ 'Party' ] . strip ( ) #NEWLINE# rr_kwargs . update ( self . _build_contest_kwargs ( row ) ) #NEWLINE# rr_kwargs . update ( self . _build_candidate_kwargs ( row ) ) #NEWLINE# rr_kwargs . update ( { #NEWLINE# #INDENT# 'party' : row [ 'Party' ] . strip ( ) , #NEWLINE# 'votes' : int ( row [ 'Votes' ] . strip ( ) ) , #NEWLINE# 'ocd_id' : '{}' . format ( self . _get_ocd_id ( rr_kwargs [ 'jurisdiction' ] ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# try : #NEWLINE# #INDENT# rr_kwargs . update ( { #NEWLINE# #INDENT# 'district' : normalize_district ( self . header , row [ self . contest_index ] , row ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# district_flag = 1 #NEWLINE# #UNINDENT# results . append ( RawResult ( ** rr_kwargs ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 0 is not x ) : #NEWLINE# #INDENT# logger . info ( 'Some rows did not contain district info.' ) #NEWLINE# #UNINDENT# #UNINDENT# '\n        Many county files *only* have local races, such as schoolboard or\n        fire chief races. Since openstates does not want these results,\n        the entire files end up being skipped. To clarify the error message,\n        we print our own if RawResult tries to insert nothing into mongodb\n\n        ' #NEWLINE# try : #NEWLINE# #INDENT# RawResult . objects . insert ( results ) #NEWLINE# #UNINDENT# except errors . InvalidOperation : #NEWLINE# #INDENT# logger . error ( '\tNo raw results loaded' )