Started working on adding romanizations to DB
This commit is contained in:
@@ -196,27 +196,27 @@ def ulca_api():
|
|||||||
@app.route('/romanize', methods=['POST'])
|
@app.route('/romanize', methods=['POST'])
|
||||||
def romanizeHandler():
|
def romanizeHandler():
|
||||||
langCodeLookup = {
|
langCodeLookup = {
|
||||||
"as": "as",
|
|
||||||
"bn": "bn",
|
|
||||||
"gom": "gom",
|
|
||||||
"gu": "gu",
|
|
||||||
"hi": "hi",
|
"hi": "hi",
|
||||||
"kn": "kn",
|
"bn": "bn",
|
||||||
"mai": "mai",
|
|
||||||
"ml": "ml",
|
|
||||||
"mni-Mtei": "mni",
|
|
||||||
"mr": "mr",
|
"mr": "mr",
|
||||||
"ne": "ne",
|
|
||||||
"or": "or",
|
|
||||||
"pa": "pa",
|
|
||||||
"sd": "sd",
|
|
||||||
"ta": "ta",
|
"ta": "ta",
|
||||||
"te": "te",
|
"te": "te",
|
||||||
|
"kn": "kn",
|
||||||
|
"ml": "ml",
|
||||||
|
"or": "or",
|
||||||
|
"gu": "gu",
|
||||||
"ur": "ur",
|
"ur": "ur",
|
||||||
|
"as": "as",
|
||||||
|
"pa": "pa",
|
||||||
|
"mai": "mai",
|
||||||
|
"ne": "ne",
|
||||||
|
"gom": "gom",
|
||||||
"tcy": "kn", # Tulu uses Kannada script
|
"tcy": "kn", # Tulu uses Kannada script
|
||||||
"awa": "hi", # Awadhi uses Hindi script
|
|
||||||
"doi": "hi", # Dogri uses Hindi script
|
|
||||||
"bho": "hi", # Bhojpuri uses Hindi script
|
"bho": "hi", # Bhojpuri uses Hindi script
|
||||||
|
"doi": "hi", # Dogri uses Hindi script
|
||||||
|
"mni-Mtei": "mni",
|
||||||
|
"sd": "sd",
|
||||||
|
"awa": "hi", # Awadhi uses Hindi script
|
||||||
}
|
}
|
||||||
rtv = dict()
|
rtv = dict()
|
||||||
|
|
||||||
@@ -224,6 +224,7 @@ def romanizeHandler():
|
|||||||
|
|
||||||
# Check if database contains the romanizations already
|
# Check if database contains the romanizations already
|
||||||
englishWord = data['en']
|
englishWord = data['en']
|
||||||
|
rtv["en"] = englishWord
|
||||||
print(englishWord)
|
print(englishWord)
|
||||||
con = sqlite3.connect("../translations.db")
|
con = sqlite3.connect("../translations.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
@@ -234,7 +235,7 @@ def romanizeHandler():
|
|||||||
romanizationsDict = []
|
romanizationsDict = []
|
||||||
if len(romanizations) > 0:
|
if len(romanizations) > 0:
|
||||||
for row in romanizations:
|
for row in romanizations:
|
||||||
row_dict = {columnNames[i]: row[i] for i in range(len(columns))}
|
row_dict = {columnNames[i]: row[i] for i in range(len(langCodeLookup)+1)} # The '+1' is because of English, which isn't in langCodeLookup
|
||||||
romanizationsDict.append(row_dict)
|
romanizationsDict.append(row_dict)
|
||||||
json_data = json.dumps(romanizationsdata, indent=4)
|
json_data = json.dumps(romanizationsdata, indent=4)
|
||||||
print(json_data)
|
print(json_data)
|
||||||
@@ -250,6 +251,9 @@ def romanizeHandler():
|
|||||||
rtv[key] = responseJson['result']
|
rtv[key] = responseJson['result']
|
||||||
|
|
||||||
rtvJson = jsonify(rtv)
|
rtvJson = jsonify(rtv)
|
||||||
|
rtv["en"] = englishWord
|
||||||
|
cur.execute("INSERT INTO romanizations VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", tuple(rtv.values()))
|
||||||
|
con.commit()
|
||||||
|
|
||||||
con.close()
|
con.close()
|
||||||
return rtvJson
|
return rtvJson
|
||||||
|
Reference in New Issue
Block a user