-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmozilla_devices.py
More file actions
43 lines (32 loc) · 1.02 KB
/
mozilla_devices.py
File metadata and controls
43 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from requests import Session
from requests.models import Response
from config import logger
from pydantic import BaseModel
CATALOG_URL = "https://code.cdn.mozilla.net/devices/devices.json"
class Device(BaseModel):
name: str
width: int
height: int
pixelRatio: float
userAgent: str
touch: bool
os: str
class Devices(BaseModel):
TYPES: list[str]
phones: list[Device]
tablets: list[Device]
laptops: list[Device]
televisions: list[Device]
def get_useragent_list() -> list[str]:
logger.debug(msg=f"Querying endpoint: {CATALOG_URL}")
catalog_response: Response = Session().get(url=CATALOG_URL)
if not catalog_response.ok:
logger.warning(msg="Unable to get useragent list.")
return []
devices: Devices = Devices.model_validate(obj=catalog_response.json())
return (
[phone.userAgent for phone in devices.phones]
if devices.phones
else [tablet.userAgent for tablet in devices.tablets]
)
useragent_list: list[str] = get_useragent_list()