Exemplo n.º 1
0
class CircuitCourtReader:
    def __init__(self):
        self.fips_code = ''
        self.case_type = ''
        self.opener = CircuitCourtOpener()
        self.searches_on_session = 0

    def manage_opener(self):
        self.searches_on_session += 1
        if self.searches_on_session > 100:
            print 'RESETTING OPENER'
            self.log_off()
            sleep(2)
            self.connect()
            self.searches_on_session = 0
            self.fips_code = ''
            print 'RESET SUCCESSFUL'

    def connect(self):
        soup = self.opener.open_welcome_page()
        self.courts = circuitcourtparser.parse_court_names(soup)
        return self.courts

    def log_off(self):
        self.opener.log_off()

    def change_court(self, fips_code, case_type):
        if fips_code != self.fips_code or case_type != self.case_type:
            print 'CHANGING COURT TO', fips_code
            self.opener.change_court(fips_code,
                                     self.courts[fips_code]['full_name'])
            self.fips_code = fips_code
            self.case_type = case_type
            sleep(1)

    def get_case_details_by_number(self,
                                   fips,
                                   case_type,
                                   case_number,
                                   case_details_url=None):
        self.manage_opener()
        category_code = 'R'
        if case_type == 'civil':
            category_code = 'CIVIL'
        self.change_court(fips, case_type)
        soup = self.opener.do_case_number_search(fips, case_number,
                                                 category_code)
        pleadings_soup = self.opener.do_case_number_pleadings_search(
            fips, case_number, category_code)
        services_soup = self.opener.do_case_number_services_search(
            fips, case_number, category_code)
        self.opener.return_to_main_menu(fips)
        if case_type == 'civil':
            case_details = circuitcourtparser.parse_civil_case_details(soup)
        else:
            case_details = circuitcourtparser.parse_case_details(soup)
        case_details['Pleadings'] = circuitcourtparser.parse_pleadings_table(
            pleadings_soup, case_type)
        case_details['Services'] = circuitcourtparser.parse_services_table(
            services_soup, case_type)
        return case_details

    def get_cases_by_name(self, fips_code, case_type, name):
        self.manage_opener()
        category_code = 'R'
        if case_type == 'civil':
            category_code = 'CIVIL'
        self.change_court(fips_code, case_type)
        cases = []
        soup = self.opener.do_name_search(fips_code, name, category_code)
        all_found = circuitcourtparser.parse_name_search(soup, name, cases)
        while not all_found:
            sleep(1)
            soup = self.opener.continue_name_search(fips_code, category_code)
            all_found = circuitcourtparser.parse_name_search(soup, name, cases)
        return cases

    def get_cases_by_date(self, fips_code, case_type, date):
        self.manage_opener()
        category_code = 'R'
        if case_type == 'civil':
            category_code = 'CIVIL'
        self.change_court(fips_code, case_type)
        cases = []
        soup = self.opener.do_date_search(fips_code, date, category_code)
        all_found = circuitcourtparser.parse_date_search(soup, cases)
        print 'FINAL PAGE', all_found
        while not all_found:
            sleep(1)
            soup = self.opener.continue_date_search(fips_code, category_code)
            all_found = circuitcourtparser.parse_date_search(soup, cases)
            print 'FINAL PAGE', all_found
        return cases
Exemplo n.º 2
0
class CircuitCourtReader:
    def __init__(self):
        self.fips_code = ''
        self.opener = CircuitCourtOpener()
        self.searches_on_session = 0

    def manage_opener(self):
        self.searches_on_session += 1
        if self.searches_on_session > 100:
            print 'RESETTING OPENER'
            self.log_off()
            sleep(2)
            self.connect()
            self.searches_on_session = 0
            self.fips_code = ''
            print 'RESET SUCCESSFUL'

    def connect(self):
        soup = self.opener.open_welcome_page()
        self.courts = circuitcourtparser.parse_court_names(soup)
        return self.courts

    def log_off(self):
        self.opener.log_off()

    def change_court(self, fips_code):
        if fips_code != self.fips_code:
            print 'Changing court'
            self.opener.change_court(fips_code, \
                                     self.courts[fips_code]['full_name'])
            self.fips_code = fips_code
            sleep(1)

    def get_case_details_by_number(self, fips_code, case_type, case_number, case_details_url=None):
        self.manage_opener()
        category_code = 'R'
        if case_type == 'civil':
            category_code = 'CIVIL'
        self.change_court(fips_code)
        soup = self.opener.do_case_number_search(fips_code, case_number, category_code)
        if case_type == 'civil':
            return circuitcourtparser.parse_civil_case_details(soup)
        return circuitcourtparser.parse_case_details(soup)

    def get_cases_by_name(self, fips_code, case_type, name):
        self.manage_opener()
        category_code = 'R'
        if case_type == 'civil':
            category_code = 'CIVIL'
        self.change_court(fips_code)
        cases = []
        soup = self.opener.do_name_search(fips_code, name, category_code)
        all_found = circuitcourtparser.parse_name_search(soup, name, cases)
        while not all_found:
            sleep(1)
            soup = self.opener.continue_name_search(fips_code, category_code)
            all_found = circuitcourtparser.parse_name_search(soup, name, cases)
        return cases

    def get_cases_by_date(self, fips_code, case_type, date):
        self.manage_opener()
        category_code = 'R'
        if case_type == 'civil':
            category_code = 'CIVIL'
        self.change_court(fips_code)
        cases = []
        soup = self.opener.do_date_search(fips_code, date, category_code)
        all_found = circuitcourtparser.parse_date_search(soup, cases)
        print 'FINAL PAGE', all_found
        while not all_found:
            sleep(1)
            soup = self.opener.continue_date_search(fips_code, category_code)
            all_found = circuitcourtparser.parse_date_search(soup, cases)
            print 'FINAL PAGE', all_found
        return cases