weblate/scripts/generate-aws-languages
2023-08-01 12:12:57 +02:00

31 lines
672 B
Python
Executable file

#!/usr/bin/env python
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import re
import requests
URL = "https://docs.aws.amazon.com/translate/latest/dg/what-is.html"
LANG_RE = re.compile(".*<td> *([a-z][a-z](-[A-Z][A-Z])?) *</td>.*")
CODES = set()
response = requests.get(URL, timeout=1)
parse = False
for line in response.text.splitlines():
if parse:
match = LANG_RE.match(line)
if match:
CODES.add(match[1])
elif "</table>" in line:
break
elif "<th>Language Code" in line:
parse = True
for code in sorted(CODES):
print(f" {code!r},")