generated from AlexTraveylan/Template-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DEMARES Timothee
committed
Oct 3, 2024
1 parent
6699fc2
commit cb2292e
Showing
5 changed files
with
144 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,11 @@ | ||
from functools import cached_property | ||
from app.core.insight.interface import ( | ||
Insight, | ||
) | ||
|
||
import requests | ||
|
||
from app.adapter.exception.app_exception import AppError | ||
from app.core.insight.interface import Insight, InsightContent, endpoint | ||
from app.core.settings import SETTINGS | ||
class MobileInsight(Insight): | ||
_STATEGY = "mobile" | ||
|
||
|
||
class GoogleInsight(Insight): | ||
""" | ||
Attributes | ||
---------- | ||
url : str | ||
The URL to test | ||
Methods | ||
------- | ||
load() -> dict: | ||
Load the insights from the Google API | ||
get_desktop_result() -> InsightContent: | ||
Get the insights for the desktop version | ||
get_mobile_result() -> InsightContent: | ||
Get the insights for the mobile version | ||
""" | ||
|
||
def __init__(self, url: str, strategy: str) -> None: | ||
self.url = url | ||
self.strategy = strategy | ||
self._api_key = SETTINGS.GOOGLE_INSIGHTS_API_KEY | ||
|
||
@cached_property | ||
def load(self) -> dict: | ||
api_url = endpoint(self.url, self.api_key) | ||
|
||
response = requests.get(api_url) | ||
|
||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
raise AppError(f"Erreur {response.status_code}: {response.text}") | ||
|
||
def get_desktop_result(self) -> InsightContent: | ||
pass | ||
class DestopInsight(Insight): | ||
_STATEGY = "desktop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pydantic-settings | ||
requests | ||
pydantic |