Add `METARService` for retrieving METAR data and integrate it with `Application`

- Implement `METARService` to fetch METAR data from the CheckWX API.
- Add `requests` dependency to `pyproject.toml`.
- Update `Application` to initialize and use `METARService`.
This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2025-10-31 17:59:27 -03:00
parent c35b700e06
commit dc6528e308
4 changed files with 27 additions and 3 deletions

View File

@ -19,7 +19,8 @@ classifiers = [
dependencies = [
"tomli",
"tomli_w",
"rich"
"rich",
"requests"
]

View File

@ -1,8 +1,7 @@
import argparse
import sys
from metar_navigate.services import METARService
from metar_navigate.ui import RichInterface
from metar_navigate.utils import ConfigManager
@ -11,6 +10,7 @@ class Application:
self.parser = None
self.args = None
self.config = ConfigManager()
self.METARService = METARService(self)
self.ui = None
self.is_configured = False

View File

@ -0,0 +1,20 @@
import requests
import json
class METARService:
def __init__(self,parent):
self.__parent = parent
self.url = "https://api.checkwx.com/metar/"
def request_metar(self,ICAO_code):
url = self.url + ICAO_code
header = {
'X-API-Key':self.__parent.config.get_data("checkwx_api_key").get("checkwx_api_key")
}
if self.__parent.args.detailed:
url = url + "/decoded"
response = requests.request('GET', url,headers=header)
return response
def get_metar(self,ICAO_code):
request = self.request_metar(ICAO_code)
return request

View File

@ -0,0 +1,3 @@
from .METARSerice import METARService
__all__ = ["METARService"]