From 770a14d0574ad0e78af6348915a16a9fd18c08fc Mon Sep 17 00:00:00 2001 From: AlexTraveylan Date: Tue, 1 Oct 2024 22:53:16 +0200 Subject: [PATCH] Update README and implement Google Insights API integration in main app with settings management. Add required packages in requirements.txt --- README.md | 4 ++-- app/core/settings.py | 11 +++++++++++ app/main.py | 16 +++++++++++++++- requirements.txt | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 app/core/settings.py diff --git a/README.md b/README.md index 09fee36..31551c1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Python Template +# Eco Design ## Description -This is a Python project that uses pytest for testing and is configured for development in Visual Studio Code. It also includes a Dockerfile for containerization. +https://developers.google.com/speed/docs/insights/v5/get-started?hl=fr ## Project Structure diff --git a/app/core/settings.py b/app/core/settings.py new file mode 100644 index 0000000..bfd2a6d --- /dev/null +++ b/app/core/settings.py @@ -0,0 +1,11 @@ +from pydantic_settings import BaseSettings + + +class Settings(BaseSettings): + GOOGLE_INSIGHTS_API_KEY: str + + class Config: + env_file = ".env" + + +SETTINGS = Settings() diff --git a/app/main.py b/app/main.py index fe71238..1e6891e 100644 --- a/app/main.py +++ b/app/main.py @@ -5,15 +5,29 @@ import logging from atexit import register +import requests + from app.core.constants import LOGGER_NAME +from app.core.settings import SETTINGS logger = logging.getLogger(LOGGER_NAME) def main(): """Entry point for the application.""" + API_KEY = SETTINGS.GOOGLE_INSIGHTS_API_KEY + + url = "https://www.alextraveylan.fr" + api_url = f"https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url={url}&key={API_KEY}" + + response = requests.get(api_url) - logger.info("Application started.") + # Vérifier si la requête s'est bien déroulée + if response.status_code == 200: + json_response = response.json() + print(json_response) + else: + print(f"Erreur {response.status_code}: {response.text}") @register diff --git a/requirements.txt b/requirements.txt index e69de29..794e89e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,2 @@ +pydantic-settings +requests