Skip to content

Commit

Permalink
Merge pull request #24 from joergschultzelutter/23-metar-request-caus…
Browse files Browse the repository at this point in the history
…es-crash

Safety net for METAR data in case no ICAO code is specified
  • Loading branch information
joergschultzelutter authored Apr 11, 2024
2 parents 69ae55a + 845abdb commit 6e5487d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Python implementation of a multi-purpose APRS daemon (WX/METAR/TAF/CWOP reports,
- Automatic detection of incoming duplicate / delayed APRS message requests
- Full UTF-8 support for incoming messages. For outgoing APRS messages, the configuration can be set to either 'plain ASCII' (default) or UTF-8. Email messages are not affected by this restriction

## MPAD on YouTube

Thank you Jason/KM4ACK for your kind video review!
[![MPAD on YouTube](https://img.youtube.com/vi/75W0UTL5eOY/0.jpg)](https://www.youtube.com/watch?v=75W0UTL5eOY)

## Sample dialogue with MPAD

![Screencast](https://github.com/joergschultzelutter/mpad/blob/master/docs/screencast.gif)
Expand Down
17 changes: 13 additions & 4 deletions src/airport_data_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ def get_metar_data(icao_code: str, keyword: str = None, full_msg: bool = False):

assert keyword in ("metar", "taf")

# These are our default values
response: str = "NOTFOUND"
success: bool = False

# safety net for https://github.com/joergschultzelutter/mpad/issues/23
if not icao_code:
logger.debug(
msg="Tried to call 'get_metar_data' without specifying an ICAO code"
)
return success, response

# prepare the request parameters
# false = request METAR data but no TAF data

Expand All @@ -182,9 +193,6 @@ def get_metar_data(icao_code: str, keyword: str = None, full_msg: bool = False):
logger.error(msg="{e}")
resp = None

response: str = "NOTFOUND"
success: bool = False

if resp:
if resp.status_code == 200:
soup = BeautifulSoup(resp.text, features="html.parser")
Expand Down Expand Up @@ -411,7 +419,8 @@ def get_nearest_icao(latitude: float, longitude: float):


if __name__ == "__main__":
logger.info(get_metar_data("EDDL"))
logger.info(get_metar_data(icao_code="EDDL", keyword="metar"))
logger.info(get_metar_data(icao_code=None, keyword="taf"))
logger.info(validate_iata("KLV"))
logger.info(validate_icao("EDDF"))
logger.info(get_nearest_icao(51.538882, 8.32679))
2 changes: 1 addition & 1 deletion src/mpad_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
# Program version
#
mpad_version: str = "0.42"
mpad_version: str = "0.43"
#
###########################
# Constants, do not change#
Expand Down
2 changes: 1 addition & 1 deletion src/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def testcall(message_text: str, from_callsign: str):


if __name__ == "__main__":
testcall(message_text="taf df1jsl-1", from_callsign="df1jsl-1")
testcall(message_text="metars bli", from_callsign="KI7JOM-10")

0 comments on commit 6e5487d

Please sign in to comment.