language-data/add-iso
Michal Čihař 9812558e7d Apply black code formatter
Signed-off-by: Michal Čihař <michal@cihar.com>
2019-04-17 10:56:26 +02:00

29 lines
833 B
Python
Executable file

#! /usr/bin/env python3
import json
import sys
names = {}
with open("/usr/share/iso-codes/json/iso_639-2.json", "r") as handle:
for item in json.load(handle)["639-2"]:
for value in ("alpha_2", "alpha_3"):
if value in item:
names[item[value]] = item["name"]
with open("/usr/share/iso-codes/json/iso_639-3.json", "r") as handle:
for item in json.load(handle)["639-3"]:
for value in ("alpha_2", "alpha_3"):
if value in item:
names[item[value]] = item["name"]
with open("languages.csv", "r") as handle:
lines = handle.readlines()
for code in sys.argv[1:]:
lines.append(
"{};{};{};{}\n".format(code, names[code].split(";")[-1].strip(), 2, "n != 1")
)
with open("languages.csv", "w") as handle:
handle.writelines(sorted(lines))