Maintain order on languages.
parent
f20fc76081
commit
0b9a721368
|
@ -52,19 +52,19 @@ def load_languages(conn):
|
|||
cursor = None
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
for code, name in code_to_lang.items():
|
||||
for pos, (code, name) in enumerate(list(code_to_lang.items())):
|
||||
cursor.execute(
|
||||
f"""
|
||||
INSERT INTO {SCHEMA_NAME}.{LANG_TABLE_NAME}
|
||||
(code, name)
|
||||
(code, name, pos)
|
||||
VALUES
|
||||
(%s, %s)
|
||||
(%s, %s, %s)
|
||||
ON CONFLICT
|
||||
(code)
|
||||
DO UPDATE SET
|
||||
name = EXCLUDED.name;
|
||||
""",
|
||||
[code, name],
|
||||
[code, name, pos],
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import enum
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
class Site(enum.Enum):
|
||||
|
@ -109,6 +110,10 @@ class Language(enum.Enum):
|
|||
zu_ZA = "isiZulu"
|
||||
|
||||
|
||||
code_to_lang = {lang.name.replace("_", "-"): lang.value for lang in Language}
|
||||
code_to_lang = OrderedDict(
|
||||
[(lang.name.replace("_", "-"), lang.value) for lang in Language]
|
||||
)
|
||||
|
||||
lang_to_code = {lang.value: lang.name.replace("_", "-") for lang in Language}
|
||||
lang_to_code = OrderedDict(
|
||||
[(lang.value, lang.name.replace("_", "-")) for lang in Language]
|
||||
)
|
||||
|
|
|
@ -27,6 +27,7 @@ CREATE TABLE coach_scraper.languages
|
|||
( id SERIAL PRIMARY KEY
|
||||
, code VARCHAR(8) NOT NULL
|
||||
, name VARCHAR(128) NOT NULL
|
||||
, pos INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS
|
||||
|
|
Loading…
Reference in New Issue