Skip to content

Commit

Permalink
Update README and implement Google Insights API integration in main a…
Browse files Browse the repository at this point in the history
…pp with settings management. Add required packages in requirements.txt
  • Loading branch information
AlexTraveylan committed Oct 1, 2024
1 parent baf2bfd commit 770a14d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 11 additions & 0 deletions app/core/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
GOOGLE_INSIGHTS_API_KEY: str

class Config:
env_file = ".env"


SETTINGS = Settings()
16 changes: 15 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pydantic-settings
requests

0 comments on commit 770a14d

Please sign in to comment.