<s> from django . core . management . base import BaseCommand , CommandError <EOL> from dateutil . parser import parse as dateparse <EOL> from parsing . form_parser import form_parser , ParserMissingError <EOL> from parsing . filing import filing <EOL> from parsing . read_FEC_settings import FILECACHE_DIRECTORY <EOL> from fec_alerts . models import new_filing <EOL> from fec_alerts . utils . form_mappers import * <EOL> from shared_utils . cycle_utils import get_cycle_from_date <EOL> from django . db import connection , transaction <EOL> verbose = True <EOL> cursor = connection . cursor ( ) <EOL> """<STR_LIT>""" <EOL> def process_new_filing ( thisnewfiling , fp = None , filing_time = None , filing_time_is_exact = False ) : <EOL> """<STR_LIT>""" <EOL> if not fp : <EOL> fp = form_parser ( ) <EOL> f1 = filing ( thisnewfiling . filing_number ) <EOL> if f1 . get_error ( ) : <EOL> return False <EOL> form = f1 . get_form_type ( ) <EOL> version = f1 . get_version ( ) <EOL> if not thisnewfiling . form_type : <EOL> thisnewfiling . form_type = form <EOL> try : <EOL> if thisnewfiling . form_type [ - <NUM_LIT:1> ] . upper ( ) == '<STR_LIT:A>' : <EOL> thisnewfiling . is_amendment = True <EOL> except IndexError : <EOL> pass <EOL> if not fp . is_allowed_form ( form ) : <EOL> if verbose : <EOL> print "<STR_LIT>" % ( form , thisnewfiling . filing_number ) <EOL> if thisnewfiling . is_amendment : <EOL> thisnewfiling . save ( ) <EOL> return True <EOL> header = f1 . get_first_row ( ) <EOL> header_line = fp . parse_form_line ( header , version ) <EOL> amended_filing = None <EOL> if f1 . is_amendment : <EOL> amended_filing = f1 . headers [ '<STR_LIT>' ] <EOL> from_date = None <EOL> through_date = None <EOL> try : <EOL> if header_line [ '<STR_LIT>' ] : <EOL> from_date = dateparse ( header_line [ '<STR_LIT>' ] ) <EOL> if from_date : <EOL> thisnewfiling . cycle = get_cycle_from_date ( from_date ) <EOL> except KeyError : <EOL> print "<STR_LIT>" <EOL> pass <EOL> try : <EOL> if header_line [ '<STR_LIT>' ] : <EOL> through_date = dateparse ( header_line [ '<STR_LIT>' ] ) <EOL> if through_date : <EOL> thisnewfiling . cycle = get_cycle_from_date ( through_date ) <EOL> except KeyError : <EOL> print "<STR_LIT>" <EOL> pass <EOL> thisnewfiling . fec_id = f1 . headers [ '<STR_LIT>' ] <EOL> thisnewfiling . coverage_from_date = from_date <EOL> thisnewfiling . coverage_to_date = through_date <EOL> thisnewfiling . is_amendment = f1 . is_amendment <EOL> thisnewfiling . amends_filing = amended_filing <EOL> thisnewfiling . amendment_number = f1 . headers [ '<STR_LIT>' ] or None <EOL> thisnewfiling . header_data = header_line <EOL> print thisnewfiling . __dict__ <EOL> thisnewfiling . save ( ) <EOL> return True </s>
