def wmo_importer(url='http://tgftp.nws.noaa.gov/data/nsd_bbsss.txt'):
if PY2:
delimiter = b';'
data = urlopen(url)
else:
delimiter = ';'
import codecs
data = codecs.iterdecode(urlopen(url), 'utf-8')
reader = csv.reader(data, delimiter=delimiter, quoting=csv.QUOTE_NONE)
def geo_normalize(value):
# recognize NSEW or undefined (which is interpreted as North)
orientation = value[-1]
sign = -1 if orientation in 'SW' else 1
coords = value if orientation not in 'NEWS' else value[:-1]
coords += '-0-0' # ensure missing seconds or minutes are 0
degrees, minutes, seconds = map(float, coords.split('-', 3)[:3])
return sign * (degrees + (minutes / 60) + (seconds / 3600))
not_airport = '----'
for row in reader:
name = row[0] + row[1] if row[2] == not_airport else row[2]
yield name, geo_normalize(row[8]), geo_normalize(row[7])
# dependence between hashtag's precision and distance accurate calculating
# in fact it's sizes of grids in km
评论列表
文章目录