summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2014-02-18 20:05:13 +0000
committerNathan Kinkade <nath@nkinka.de>2014-02-18 20:05:13 +0000
commit4a41a1fe7c3c5f88259cd05e5f5b0c7362b78d3b (patch)
treec0adde2ceb4a5ee94efee66df54533746a5161d2
parent25abc7ff120c4dea3c35203eefcf75c5a319f98c (diff)
Don't skip a case when warrant_type isn't found since it's now not there on every case. Also, exit any try/except statement upon a KeyboardInterrupt exception... jeez.
-rwxr-xr-xmiami_dade_clerk_courts.py42
1 files changed, 38 insertions, 4 deletions
diff --git a/miami_dade_clerk_courts.py b/miami_dade_clerk_courts.py
index 7643e95..c062216 100755
--- a/miami_dade_clerk_courts.py
+++ b/miami_dade_clerk_courts.py
@@ -117,6 +117,8 @@ def set_asp_vars():
field_values['viewstate'] = soup.find(id="__VIEWSTATE")['value']
field_suffix_string = soup.find(title="YY")['id']
field_values['field_suffix'] = field_suffix_string.split('_')[-1]
+ except KeyboardInterrupt:
+ raise
except:
logging.error('Failed to get initial ASP variables. %s' % sys.exc_info()[0])
return False
@@ -148,6 +150,8 @@ def fetch_page(post_fields):
# Reset base ASP vars just in case
set_asp_vars()
logging.error('%s: Also resetting ASP vars just in case.' % (current_case))
+ except KeyboardInterrupt:
+ raise
except:
logging.error('%s: fetch_page() exception %s - %s'
% (current_case, sys.exc_info()[0], sys.exc_info()[1]))
@@ -163,6 +167,8 @@ def check_case_not_found(case_soup):
try:
error_text = case_soup.find(id='ctl00_cphPage_lblSearchError').text
+ except KeyboardInterrupt:
+ raise
except:
return False
else:
@@ -180,6 +186,8 @@ def check_dockets_not_found(dockets_soup):
try:
error_text = dockets_soup.find(id='ctl00_cphPage_lblCaseError').text
+ except KeyboardInterrupt:
+ raise
except:
return False
else:
@@ -260,10 +268,17 @@ def parse_case(case_soup):
for var, field_id in case_fields.iteritems():
try:
case_values[var] = case_soup.find(id=field_id).text
+ except KeyboardInterrupt:
+ raise
except:
- logging.error('%s: Failed to find field %s in soup. %s' % (current_case, var, sys.exc_info()[0]))
- logging.error('%s: Something is wrong with the soup. Here it is: %s' % (current_case, case_soup))
- continue
+ # warrant_type won't always exist, so don't bail just because we
+ # don't find it, but otherwise do log and bail
+ if var == 'warrant_type':
+ pass
+ else:
+ logging.error('%s: Failed to find field %s in soup. %s' % (current_case, var, sys.exc_info()[0]))
+ logging.error('%s: Something is wrong with the soup. Here it is: %s' % (current_case, case_soup))
+ continue
# Try to clean up the data bit to avoid needless MySQL warnings
if not case_values['hearing_time'].strip():
@@ -281,12 +296,19 @@ def parse_case(case_soup):
date_birth = format_date(case_values['date_birth']),
date_filed = format_date(case_values['date_filed']),
date_closed = format_date(case_values['date_closed']),
- warrant_type = case_values['warrant_type'],
hearing_date = format_date(case_values['hearing_date']),
hearing_time = case_values['hearing_time'],
hearing_type = case_values['hearing_type'],
defense_attorney = case_values['defense_attorney'],
)
+
+ # warrant_type won't always exist, so check before trying to assign it
+ try:
+ new_case.warrant_type = case_values['warrant_type']
+ except KeyboardInterrupt:
+ raise
+ except:
+ pass
db_session.add(new_case)
db_session.commit()
@@ -301,6 +323,8 @@ def parse_charges(case_soup, case_id):
try:
charges_section = case_soup.find(id="ctl00_cphPage_pnlCharges")
+ except KeyboardInterrupt:
+ raise
except:
logging.error('%s: Failed to find charges for case ID %s. %s' % (current_case, sys.exc_info()[0]))
return False
@@ -373,6 +397,8 @@ def parse_addinfo(addinfo_soup):
try:
court_case_no = addinfo_soup.find(id='ctl00_cphPage_lblCaseNumber').text
case = db_session.query(Case).filter_by(court_case_no=court_case_no).one()
+ except KeyboardInterrupt:
+ raise
except:
logging.error('%s: Error while looking for existing case in addinfo. %s' % (current_case, sys.exc_info()[0]))
return False
@@ -394,6 +420,8 @@ def parse_addinfo(addinfo_soup):
for var, field_id in case_fields.iteritems():
try:
case_values[var] = addinfo_soup.find(id=field_id).text
+ except KeyboardInterrupt:
+ raise
except:
logging.error('%s: Failed to find a value for the addinfo field %s. %s' % (current_case, sys.exc_info()[0]))
continue
@@ -421,6 +449,8 @@ def parse_akas(akas_soup, case_id):
try:
akas_count_text = akas_soup.find(id='ctl00_cphPage_lblDefendants').text
akas_count = re.match('^\d+', akas_count_text).group(0)
+ except KeyboardInterrupt:
+ raise
except:
logging.error('%s: Failed to determine akas_count %s. %s' % (current_case, sys.exc_info()[0]))
return False
@@ -451,6 +481,8 @@ def parse_akas(akas_soup, case_id):
for var, field_id in akas_fields.iteritems():
try:
akas_values[var] = akas_soup.find(id=field_id).text
+ except KeyboardInterrupt:
+ raise
except:
logging.error('%s: Failed to find a value for akas field %s. %s' % (current_case, var, sys.exc_info()[0]))
continue
@@ -479,6 +511,8 @@ def format_date(date):
return date_obj.strftime('%Y-%m-%d')
else:
return None
+ except KeyboardInterrupt:
+ raise
except:
logging.error('%s: Failed to create a date object for date %s. %s' % (current_case, date, sys.exc_info()[0]))
return None