diff --git a/ogn/parser/aprs_comment/skylines_parser.py b/ogn/parser/aprs_comment/skylines_parser.py index f89a01e..32f3658 100644 --- a/ogn/parser/aprs_comment/skylines_parser.py +++ b/ogn/parser/aprs_comment/skylines_parser.py @@ -1,6 +1,17 @@ +import re + +from ogn.parser.utils import fpm2ms +from ogn.parser.pattern import PATTERN_SKYLINES_BEACON + from .base import BaseParser class SkylinesParser(BaseParser): def __init__(self): self.beacon_type = 'skylines' + + @staticmethod + def parse_position(aprs_comment): + ac_match = re.search(PATTERN_SKYLINES_BEACON, aprs_comment) + return {'id': ac_match.group('id'), + 'climb_rate': int(ac_match.group('climb_rate')) * fpm2ms if ac_match.group('climb_rate') else None} diff --git a/ogn/parser/pattern.py b/ogn/parser/pattern.py index 0687bc5..a2091cf 100644 --- a/ogn/parser/pattern.py +++ b/ogn/parser/pattern.py @@ -16,6 +16,11 @@ PATTERN_NAVITER_BEACON = re.compile(""" (?P[+-][\d.]+)rot """, re.VERBOSE | re.MULTILINE) +PATTERN_SKYLINES_BEACON = re.compile(""" + id(?P\d+)\s + (?P[+-]\d+)fpm +""", re.VERBOSE | re.MULTILINE) + PATTERN_SPIDER_BEACON = re.compile(""" id(?P[\d-]+)\s (?P[+-]\d+)dB\s diff --git a/tests/parser/test_parse_skylines.py b/tests/parser/test_parse_skylines.py new file mode 100644 index 0000000..b0f6f79 --- /dev/null +++ b/tests/parser/test_parse_skylines.py @@ -0,0 +1,16 @@ +import unittest + +from ogn.parser.utils import ms2fpm +from ogn.parser.aprs_comment.skylines_parser import SkylinesParser + + +class TestStringMethods(unittest.TestCase): + def test(self): + message = SkylinesParser.parse_position("id2816 -015fpm") + + self.assertEqual(message['id'], "2816") + self.assertAlmostEqual(message['climb_rate'] * ms2fpm, -15, 2) + + +if __name__ == '__main__': + unittest.main()