weblate/scripts/generate-aws-languages
Michal Čihař 4c47dced90 Machinery: Update list of Amazon Translate languages
There is now helper script to fetch current list of langauges from the
documentation.

They really should have an API for this as any other service does...

Fixes #5299
2021-01-31 20:22:14 +01:00

27 lines
563 B
Python
Executable file

#!/usr/bin/env python
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)
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}",')