-
Notifications
You must be signed in to change notification settings - Fork 1
/
mozilla_devices.py
29 lines (23 loc) · 939 Bytes
/
mozilla_devices.py
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
from enum import Enum
from amazon_feed_data import FeedConfig
CATALOG_URL = "https://code.cdn.mozilla.net/devices/devices.json"
class DeviceType(Enum):
PHONES = "phones"
TABLETS = "tablets"
LAPTOPS = "laptops"
TELEVISIONS = "televisions"
def get_useragent_list(device_type: DeviceType, config: FeedConfig) -> list[str]:
config.logger.debug(f"Querying endpoint: {CATALOG_URL}")
catalog_response = config.session.get(CATALOG_URL)
catalog_json: dict = catalog_response.json() if catalog_response.ok else None
if catalog_response.ok:
useragent_list: list[str] = [
device["userAgent"] for device in catalog_json[device_type.value]
]
config.logger.info(
f"Found {len(useragent_list)} user agents for {device_type.name.lower()}"
)
return useragent_list
else:
config.logger.warning("Unable to get useragent list.")
return []