Skip to content

Commit

Permalink
Added simple search for the right worksheet
Browse files Browse the repository at this point in the history
This was necessary because apparently the worksheet names aren't
consistent between different census datasets, so we just search for a
case-insensitive substring to match all the variations.
  • Loading branch information
jtsymon committed Jul 30, 2016
1 parent 1a5fb98 commit fb39ed2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions census.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
read_only=True
)

ws = wb["2 Area unit"]
worksheet_matcher= re.compile(r'area unit', re.I)
ws = None
for name in wb.sheetnames:
if worksheet_matcher.search(name):
ws = wb[name]
break
if ws is None:
raise Exception("Failed to detect worksheet")

rows = iter(ws.rows)

Expand All @@ -31,7 +38,7 @@
area_unit_column = None
area_unit_matcher = re.compile(r'area unit code', re.I)

census_year_matcher = re.compile(r'^[\d]+ Census', re.I)
census_year_matcher = re.compile(r'[\d]+ Census', re.I)

h1 = next(rows)
h2 = next(rows)
Expand Down

0 comments on commit fb39ed2

Please sign in to comment.