forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alexa_locales.py
67 lines (52 loc) · 2.12 KB
/
alexa_locales.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Check if upstream Alexa locales are subset of the core Alexa supported locales."""
from pprint import pprint
import re
from bs4 import BeautifulSoup
import requests
from homeassistant.components.alexa import capabilities
SITE = (
"https://developer.amazon.com/en-GB/docs/alexa/device-apis/list-of-interfaces.html"
)
def run_script() -> None:
"""Run the script."""
response = requests.get(SITE, timeout=10)
soup = BeautifulSoup(response.text, "html.parser")
table = soup.find("table")
table_body = table.find_all("tbody")[-1]
rows = table_body.find_all("tr")
data = [[ele.text.strip() for ele in row.find_all("td") if ele] for row in rows]
upstream_locales_raw = {row[0]: row[3] for row in data}
language_pattern = re.compile(r"^[a-z]{2}-[A-Z]{2}$")
upstream_locales = {
upstream_interface: {
name
for word in upstream_locale.split(" ")
if (name := word.strip(",")) and language_pattern.match(name) is not None
}
for upstream_interface, upstream_locale in upstream_locales_raw.items()
if upstream_interface.count(".") == 1 # Skip sub-interfaces
}
interfaces_missing = {}
interfaces_nok = {}
interfaces_ok = {}
for upstream_interface, upstream_locale in upstream_locales.items():
core_interface_name = upstream_interface.replace(".", "")
core_interface = getattr(capabilities, core_interface_name, None)
if core_interface is None:
interfaces_missing[upstream_interface] = upstream_locale
continue
core_locale = core_interface.supported_locales
if not upstream_locale.issubset(core_locale):
interfaces_nok[core_interface_name] = core_locale
else:
interfaces_ok[core_interface_name] = core_locale
print("Missing interfaces:")
pprint(list(interfaces_missing))
print("\n")
print("Interfaces where upstream locales are not subsets of the core locales:")
pprint(list(interfaces_nok))
print("\n")
print("Interfaces checked ok:")
pprint(list(interfaces_ok))
if __name__ == "__main__":
run_script()