metar: handle edge case for pressure parsing
parent
5cb88f3cf8
commit
caf4a464a9
26
metar.py
26
metar.py
|
@ -124,19 +124,23 @@ class Weather(object):
|
||||||
return '?'
|
return '?'
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
chunks = [self.cover]
|
||||||
|
chunks.append('{0}°C'.format(self.temperature))
|
||||||
|
|
||||||
|
if self.pressure:
|
||||||
|
chunks.append('{0} hPa'.format(self.pressure))
|
||||||
|
|
||||||
if self.conditions:
|
if self.conditions:
|
||||||
ret = "{cover}, {temperature}°C, {pressure} hPa, {conditions}, "\
|
chunks.append(self.conditions)
|
||||||
"{windnote} {wind} m/s ({windsock}) - {station} {time}"
|
|
||||||
else:
|
|
||||||
ret = "{cover}, {temperature}°C, {pressure} hPa, "\
|
|
||||||
"{windnote} {wind} m/s ({windsock}) - {station} {time}"
|
|
||||||
|
|
||||||
wind = self.wind_speed if self.wind_speed is not None else '?'
|
wind = self.wind_speed if self.wind_speed is not None else '?'
|
||||||
|
chunks.append('{note} {speed} m/s ({windsock})'.format(
|
||||||
|
note=self.describe_wind(),
|
||||||
|
speed=wind,
|
||||||
|
windsock=self.windsock()))
|
||||||
|
|
||||||
return ret.format(cover=self.cover, temperature=self.temperature,
|
ret = ', '.join(chunks) + ' - {station} {time}'
|
||||||
pressure=self.pressure, conditions=self.conditions,
|
return ret.format(station=self.station,
|
||||||
wind=wind, windnote=self.describe_wind(),
|
|
||||||
windsock=self.windsock(), station=self.station,
|
|
||||||
time=self.time.strftime("%H:%MZ"))
|
time=self.time.strftime("%H:%MZ"))
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,10 +268,10 @@ def parse(data):
|
||||||
# pressure
|
# pressure
|
||||||
pressure_re = re.compile(r"([QA])(\d+)")
|
pressure_re = re.compile(r"([QA])(\d+)")
|
||||||
m = pressure_re.search(w.metar)
|
m = pressure_re.search(w.metar)
|
||||||
if m.group(1) == 'A':
|
if m and m.group(1) == 'A':
|
||||||
# convert inHg to hPa
|
# convert inHg to hPa
|
||||||
w.pressure = round(float(m.group(2)) * 0.3386389)
|
w.pressure = round(float(m.group(2)) * 0.3386389)
|
||||||
else:
|
elif m:
|
||||||
w.pressure = int(m.group(2))
|
w.pressure = int(m.group(2))
|
||||||
|
|
||||||
return w
|
return w
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
2013/06/13 01:15
|
||||||
|
KBCB 130115Z AUTO 00000KT 10SM CLR 23/22 RMK AO2
|
Loading…
Reference in New Issue