Correlation building fixes

* weather.py(correlate): Note the updated URL to Census Bureau data
in file comments, and make the County-Public Forecast Zones
Correlation File parsing more robust against errors in the file
formatting.
This commit is contained in:
Jeremy Stanley
2014-02-13 00:48:25 +00:00
parent ae2530c01c
commit ddf8f22fe8

View File

@@ -1,7 +1,7 @@
"""Contains various object definitions needed by the weather utility.""" """Contains various object definitions needed by the weather utility."""
weather_copyright = """\ weather_copyright = """\
# Copyright (c) 2006-2012 Jeremy Stanley <fungi@yuggoth.org>. Permission to # Copyright (c) 2006-2014 Jeremy Stanley <fungi@yuggoth.org>. Permission to
# use, copy, modify, and distribute this software is granted under terms # use, copy, modify, and distribute this software is granted under terms
# provided in the LICENSE file distributed with this software. # provided in the LICENSE file distributed with this software.
#""" #"""
@@ -1226,7 +1226,7 @@ def correlate():
%s %s
# generated by %s on %s from these public domain sources: # generated by %s on %s from these public domain sources:
# #
# http://www.census.gov/geo/www/gazetteer/gazetteer2010.html # http://www.census.gov/geo/maps-data/data/gazetteer2010.html
# %s %s %s # %s %s %s
# %s %s %s # %s %s %s
# %s %s %s # %s %s %s
@@ -1545,12 +1545,12 @@ def correlate():
cpfz = {} cpfz = {}
cpfzcf = open(cpfzcf_fn) cpfzcf = open(cpfzcf_fn)
for line in cpfzcf: for line in cpfzcf:
fields = line.split("|") fields = line.strip().split("|")
if len(fields) == 11 \ if len(fields) == 11 \
and fields[0] and fields[1] and fields[9] and fields[10]: and fields[0] and fields[1] and fields[9] and fields[10]:
zone = "z".join( fields[:2] ).lower() zone = "z".join( fields[:2] ).lower()
if zone in zones: if zone in zones:
zones[zone]["centroid"] = gecos( ",".join( fields[9:] ) ) zones[zone]["centroid"] = gecos( ",".join( fields[9:11] ) )
elif fields[6]: elif fields[6]:
state = fields[0] state = fields[0]
description = fields[3] description = fields[3]