parent
1b7da6566c
commit
c9f4b4f779
|
|
@ -48,13 +48,17 @@ def parse_weather_data(body):
|
|||
body = re.sub(r"^([0-9]{3})/([0-9]{3})", "c\\1s\\2", body)
|
||||
body = body.replace('s', 'S', 1)
|
||||
|
||||
data = re.findall(r"([cSgtrpPlLs#]\d{3}|t-\d{2}|h\d{2}|b\d{5}|s\.\d{2}|s\d\.\d)", body)
|
||||
data = map(lambda x: (key_map[x[0]] , val_map[x[0]](x[1:])), data)
|
||||
# match as many parameters from the start, rest is comment
|
||||
data = re.match(r"^([cSgtrpPlLs#][0-9\-\. ]{3}|h[0-9\. ]{2}|b[0-9\. ]{5})+", body)
|
||||
|
||||
parsed.update(dict(data))
|
||||
|
||||
# strip weather data
|
||||
body = re.sub(r"([cSgtrpPlLs#][0-9\-\. ]{3}|h[0-9\. ]{2}|b[0-9\. ]{5})", '', body)
|
||||
if data:
|
||||
data = data.group()
|
||||
# split out data from comment
|
||||
body = body[len(data):]
|
||||
# parse all weather parameters
|
||||
data = re.findall(r"([cSgtrpPlLs#]\d{3}|t-\d{2}|h\d{2}|b\d{5}|s\.\d{2}|s\d\.\d)", data)
|
||||
data = map(lambda x: (key_map[x[0]] , val_map[x[0]](x[1:])), data)
|
||||
parsed.update(dict(data))
|
||||
|
||||
return (body, parsed)
|
||||
|
||||
|
|
|
|||
|
|
@ -204,11 +204,11 @@ class ParseCommentWeather(unittest.TestCase):
|
|||
def test_positionless_packet(self):
|
||||
|
||||
expected = {
|
||||
'comment': 'wRSW',
|
||||
'comment': '.ABS1.2CDF',
|
||||
'format': 'wx',
|
||||
'from': 'A',
|
||||
'path': [],
|
||||
'raw': 'A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5wRSW',
|
||||
'raw': 'A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5.ABS1.2CDF',
|
||||
'to': 'B',
|
||||
'via': '',
|
||||
'wx_raw_timestamp': '10090556',
|
||||
|
|
@ -226,11 +226,11 @@ class ParseCommentWeather(unittest.TestCase):
|
|||
}
|
||||
}
|
||||
|
||||
packet = "A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5wRSW"
|
||||
packet = "A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5.ABS1.2CDF"
|
||||
|
||||
self.assertEqual(expected, parse(packet))
|
||||
|
||||
packet2 = "A>B:_10090556c220s112g t r h b wRSW"
|
||||
packet2 = "A>B:_10090556c220s112g t r h b .ABS1.2CDF"
|
||||
expected['raw'] = packet2
|
||||
expected['weather'] = {
|
||||
"wind_direction": 220,
|
||||
|
|
@ -239,7 +239,7 @@ class ParseCommentWeather(unittest.TestCase):
|
|||
|
||||
self.assertEqual(expected, parse(packet2))
|
||||
|
||||
packet3 = "A>B:_10090556c220s112g...t...r...p...P...b.....wRSW"
|
||||
packet3 = "A>B:_10090556c220s112g...t...r...p...P...b......ABS1.2CDF"
|
||||
expected['raw'] = packet3
|
||||
expected['weather'] = {
|
||||
"wind_direction": 220,
|
||||
|
|
|
|||
Loading…
Reference in New Issue