diff --git a/metar.py b/metar.py index de63c9e..d8617da 100644 --- a/metar.py +++ b/metar.py @@ -124,20 +124,24 @@ class Weather(object): return '?' 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: - ret = "{cover}, {temperature}°C, {pressure} hPa, {conditions}, "\ - "{windnote} {wind} m/s ({windsock}) - {station} {time}" - else: - ret = "{cover}, {temperature}°C, {pressure} hPa, "\ - "{windnote} {wind} m/s ({windsock}) - {station} {time}" + chunks.append(self.conditions) 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, - pressure=self.pressure, conditions=self.conditions, - wind=wind, windnote=self.describe_wind(), - windsock=self.windsock(), station=self.station, - time=self.time.strftime("%H:%MZ")) + ret = ', '.join(chunks) + ' - {station} {time}' + return ret.format(station=self.station, + time=self.time.strftime("%H:%MZ")) def build_regex(key, classifier): @@ -264,10 +268,10 @@ def parse(data): # pressure pressure_re = re.compile(r"([QA])(\d+)") m = pressure_re.search(w.metar) - if m.group(1) == 'A': + if m and m.group(1) == 'A': # convert inHg to hPa w.pressure = round(float(m.group(2)) * 0.3386389) - else: + elif m: w.pressure = int(m.group(2)) return w diff --git a/test/metar/KBCB_2.txt b/test/metar/KBCB_2.txt new file mode 100644 index 0000000..a90d9ab --- /dev/null +++ b/test/metar/KBCB_2.txt @@ -0,0 +1,2 @@ +2013/06/13 01:15 +KBCB 130115Z AUTO 00000KT 10SM CLR 23/22 RMK AO2