kopia lustrzana https://github.com/glidernet/python-ogn-client
Parse (server) comments
rodzic
52468a4bd1
commit
8f8974446c
|
@ -1,6 +1,7 @@
|
|||
# CHANGELOG
|
||||
## Unreleased
|
||||
- parser: Added support for OGNLT24 (LT24), OGSKYL (Skylines), OGSPID (Spider) and OGSPOT (Spot)
|
||||
- parser: Added support for (server) comments
|
||||
|
||||
## 0.8.2: - 2018-01-20
|
||||
- parser: Better validation of timestamp, lat/lon and altitude
|
||||
|
|
|
@ -2,7 +2,7 @@ import re
|
|||
from datetime import datetime
|
||||
|
||||
from ogn.parser.utils import createTimestamp, parseAngle, kts2kmh, feet2m
|
||||
from ogn.parser.pattern import PATTERN_APRS_POSITION, PATTERN_APRS_STATUS
|
||||
from ogn.parser.pattern import PATTERN_APRS_POSITION, PATTERN_APRS_STATUS, PATTERN_APRS_SERVER
|
||||
from ogn.parser.exceptions import AprsParseError, OgnParseError
|
||||
|
||||
from ogn.parser.aprs_comment.ogn_parser import OgnParser
|
||||
|
@ -28,6 +28,19 @@ def parse(aprs_message, reference_date=None, reference_time=None):
|
|||
|
||||
|
||||
def parse_aprs(message, reference_date, reference_time=None):
|
||||
if message and message[0] == '#':
|
||||
match_server = re.search(PATTERN_APRS_SERVER, message)
|
||||
if match_server:
|
||||
return {'version': match_server.group('version'),
|
||||
'timestamp': datetime.strptime(match_server.group('timestamp'), "%d %b %Y %H:%M:%S %Z"),
|
||||
'server': match_server.group('server'),
|
||||
'ip_address': match_server.group('ip_address'),
|
||||
'port': match_server.group('port'),
|
||||
'aprs_type': 'server'}
|
||||
else:
|
||||
return {'comment': message,
|
||||
'aprs_type': 'comment'}
|
||||
|
||||
match_position = re.search(PATTERN_APRS_POSITION, message)
|
||||
if match_position:
|
||||
return {'name': match_position.group('callsign'),
|
||||
|
|
|
@ -3,6 +3,7 @@ import re
|
|||
|
||||
PATTERN_APRS_POSITION = re.compile(r"^(?P<callsign>.+?)>(?P<dstcall>[A-Z0-9]+),((?P<relay>[A-Za-z0-9]+)\*)?.*,(?P<receiver>.+?):/(?P<time>(([0-1]\d|2[0-3])[0-5]\d[0-5]\dh|([0-2]\d|3[0-1])([0-1]\d|2[0-3])[0-5]\dz))(?P<latitude>9000\.00|[0-8]\d{3}\.\d{2})(?P<latitude_sign>N|S)(?P<symbol_table>.)(?P<longitude>18000\.00|1[0-7]\d{3}\.\d{2}|0\d{4}\.\d{2})(?P<longitude_sign>E|W)(?P<symbol>.)(?P<course_extension>(?P<course>\d{3})/(?P<ground_speed>\d{3}))?/A=(?P<altitude>(-\d{5}|\d{6}))(?P<pos_extension>\s!W((?P<latitude_enhancement>\d)(?P<longitude_enhancement>\d))!)?(?:\s(?P<comment>.*))?$")
|
||||
PATTERN_APRS_STATUS = re.compile(r"^(?P<callsign>.+?)>(?P<dstcall>[A-Z0-9]+),.+,(?P<receiver>.+?):>(?P<time>\d{6}(h|z))\s(?P<comment>.*)$")
|
||||
PATTERN_APRS_SERVER = re.compile(r"^# aprsc (?P<version>[a-z0-9\.\-]+) (?P<timestamp>\d+ [A-Za-z]+ \d+ \d{2}:\d{2}:\d{2} GMT) (?P<server>[A-Z0-9]+) (?P<ip_address>\d+\.\d+\.\d+\.\d+):(?P<port>\d+)$")
|
||||
|
||||
PATTERN_LT24_POSITION_COMMENT = re.compile("""
|
||||
id(?P<id>\d+)\s
|
||||
|
|
|
@ -94,6 +94,24 @@ class TestStringMethods(unittest.TestCase):
|
|||
with self.assertRaises(AprsParseError):
|
||||
parse_aprs("Ulrichamn>APRS,TCPIP*,qAC,GLIDERN1:/085616h5747.30NI01324.77E&/A=12-345", reference_date=datetime(2015, 1, 1))
|
||||
|
||||
def test_bad_comment(self):
|
||||
raw_message = "# bad configured ogn receiver"
|
||||
message = parse_aprs(raw_message, reference_date=datetime(2015, 1, 1))
|
||||
|
||||
self.assertEqual(message['comment'], raw_message)
|
||||
self.assertEqual(message['aprs_type'], 'comment')
|
||||
|
||||
def test_server_comment(self):
|
||||
raw_message = "# aprsc 2.1.4-g408ed49 17 Mar 2018 09:30:36 GMT GLIDERN1 37.187.40.234:10152"
|
||||
message = parse_aprs(raw_message, reference_date=datetime(2015, 1, 1))
|
||||
|
||||
self.assertEqual(message['version'], '2.1.4-g408ed49')
|
||||
self.assertEqual(message['timestamp'], datetime(2018, 3, 17, 9, 30, 36))
|
||||
self.assertEqual(message['server'], 'GLIDERN1')
|
||||
self.assertEqual(message['ip_address'], '37.187.40.234')
|
||||
self.assertEqual(message['port'], '10152')
|
||||
self.assertEqual(message['aprs_type'], 'server')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Ładowanie…
Reference in New Issue