Ajoute les paramètre '--config' et '--location'
This commit is contained in:
41
main.py
41
main.py
@@ -1,20 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import locale
|
||||
import json
|
||||
import os
|
||||
import json
|
||||
import locale
|
||||
import pprint
|
||||
import argparse
|
||||
import requests
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from meteo.config import Config
|
||||
|
||||
yr_no_url = "https://api.met.no/weatherapi/locationforecast/2.0/"
|
||||
|
||||
|
||||
def load_args():
|
||||
"""Charge l'action et les paramêtres communs a toutes les actions."""
|
||||
parser = argparse.ArgumentParser(description="Affiche la météo")
|
||||
parser.add_argument(
|
||||
"-c",
|
||||
"--config",
|
||||
default=Path.home() / ".config" / "meteo.yaml",
|
||||
help="Chemin vers le fichier de configuration",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--location",
|
||||
default="home",
|
||||
help="",
|
||||
)
|
||||
return vars(parser.parse_args())
|
||||
|
||||
|
||||
def main():
|
||||
"""Fonction principale"""
|
||||
|
||||
conf = Config("./meteo.yaml")
|
||||
location = conf.get_location("florac")
|
||||
args = load_args()
|
||||
config_file = Path(args["config"])
|
||||
if not config_file.is_file():
|
||||
print(f"{config_file} n'est pas un fichier.")
|
||||
os._exit(1)
|
||||
|
||||
conf = Config(args["config"])
|
||||
try:
|
||||
location = conf.get_location(args["location"])
|
||||
except AttributeError:
|
||||
print(f"{args['location']} n'est pas configuré.")
|
||||
os._exit(1)
|
||||
|
||||
url = f"{yr_no_url}compact.json?lat={location['latitude']}&lon={location['longitude']}&altitude={location['altitude']}"
|
||||
headers = {"User-Agent": "DaikoMete/0.1 daiko@daiko.fr"}
|
||||
|
@@ -1,10 +1,6 @@
|
||||
locations:
|
||||
florac:
|
||||
home:
|
||||
altitude: 522
|
||||
latitude: 44.3245
|
||||
longitude: 3.5925
|
||||
|
||||
laparrouquial:
|
||||
altitude: 200
|
||||
latitude: 44.1229
|
||||
longitude: 2.0199
|
||||
|
Reference in New Issue
Block a user