Skip to content

Commit 7bc2580

Browse files
authored
Merge pull request #65 from mivek/feature/runway_error_parse
Feature/runway error parse
2 parents d99973b + 42b51bc commit 7bc2580

23 files changed

Lines changed: 641 additions & 175 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [1.9.0] - 2024-05-19
4+
5+
### Added
6+
7+
- When information about a runway is incomplete in a METAR, a `ParseError` is raised instead of `ValueError`.
8+
39
## [1.8.2] - 2024-01-14
410

511
### Fixed

metar_taf_parser/command/metar.py

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22

33
from metar_taf_parser.commons import converter
4+
from metar_taf_parser.commons.exception import ParseError
45
from metar_taf_parser.model.enum import DepositType, DepositCoverage
56
from metar_taf_parser.model.model import RunwayInfo, Metar
67
from metar_taf_parser.commons.i18n import _
@@ -41,6 +42,22 @@ def execute(self, metar: Metar, input: str):
4142
metar.altimeter = int(converter.convert_inches_mercury_to_pascal(mercury))
4243

4344

45+
def _parse_runway(matches, metar, runway):
46+
runway.name = matches[0][0]
47+
runway.indicator = matches[0][1]
48+
runway.min_range = int(matches[0][2])
49+
runway.trend = matches[0][3]
50+
metar.add_runway_info(runway)
51+
52+
53+
def _parse_runway_max_range(matches, metar, runway):
54+
runway.name = matches[0][0]
55+
runway.min_range = int(matches[0][1])
56+
runway.max_range = int(matches[0][2])
57+
runway.trend = matches[0][3]
58+
metar.add_runway_info(runway)
59+
60+
4461
class RunwayCommand:
4562
generic_regex = r'^(R\d{2}\w?/)'
4663
runway_max_range_regex = r'^R(\d{2}\w?)/(\d{4})V(\d{3,4})([UDN])?(FT)?'
@@ -79,31 +96,29 @@ def can_parse(self, input: str):
7996
def execute(self, metar: Metar, input: str):
8097
matches = self._runway_deposit_pattern.findall(input)
8198
runway = RunwayInfo()
82-
if matches:
83-
runway.name = matches[0][0]
84-
runway.deposit_type = DepositType(matches[0][1])
85-
runway.coverage = DepositCoverage(matches[0][2])
86-
runway.thickness = self.__parse_deposit_thickness(matches[0][3])
87-
runway.braking_capacity = self.__parse_deposit_braking_capacity(matches[0][4])
88-
metar.add_runway_info(runway)
89-
return
90-
91-
matches = self._runway_pattern.findall(input)
92-
if matches:
93-
runway.name = matches[0][0]
94-
runway.indicator = matches[0][1]
95-
runway.min_range = int(matches[0][2])
96-
runway.trend = matches[0][3]
97-
metar.add_runway_info(runway)
98-
return
99-
100-
matches = self._max_range_pattern.findall(input)
101-
if matches:
102-
runway.name = matches[0][0]
103-
runway.min_range = int(matches[0][1])
104-
runway.max_range = int(matches[0][2])
105-
runway.trend = matches[0][3]
106-
metar.add_runway_info(runway)
99+
try:
100+
if matches:
101+
self.__parse_runway_deposit(matches, metar, runway)
102+
return
103+
104+
matches = self._runway_pattern.findall(input)
105+
if matches:
106+
_parse_runway(matches, metar, runway)
107+
return
108+
109+
matches = self._max_range_pattern.findall(input)
110+
if matches:
111+
_parse_runway_max_range(matches, metar, runway)
112+
except ValueError:
113+
raise ParseError(_("ErrorCode.IncompleteRunwayInformation"))
114+
115+
def __parse_runway_deposit(self, matches, metar, runway):
116+
runway.name = matches[0][0]
117+
runway.deposit_type = DepositType(matches[0][1])
118+
runway.coverage = DepositCoverage(matches[0][2])
119+
runway.thickness = self.__parse_deposit_thickness(matches[0][3])
120+
runway.braking_capacity = self.__parse_deposit_braking_capacity(matches[0][4])
121+
metar.add_runway_info(runway)
107122

108123
def __parse_deposit_thickness(self, input):
109124
thickness = self._deposit_thickness.get(input, 'DepositThickness.default')

metar_taf_parser/commons/exception.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ class TranslationError(Exception):
77
def __init__(self, translation: str, message: str):
88
self.message = message
99
self.translation = translation
10+
11+
12+
class ParseError(Exception):
13+
def __init__(self, message: str):
14+
self.__message = message
15+
16+
def message(self):
17+
return self.__message
0 Bytes
Binary file not shown.
113 Bytes
Binary file not shown.

metar_taf_parser/locale/en/LC_MESSAGES/messages.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ msgstr "The airport was not found for this message."
258258
msgid "ErrorCode.InvalidMessage"
259259
msgstr "The entered message is invalid."
260260

261+
#:
262+
msgid "ErrorCode.IncompleteRunwayInformation"
263+
msgstr "The runway information is incomplete and cannot be parsed."
264+
261265
#:
262266
msgid "Flag.AMD"
263267
msgstr "amended TAF"
2.59 KB
Binary file not shown.

0 commit comments

Comments
 (0)