Rev 288 |
Rev 296 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This file is part of Tsim Apiak.
#
# Tsim Apiak is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public Licence as published by
# the Free Software Foundation, either version 3 of the Licence, or
# (at your option) any later version.
#
# In addition to this, you must also comply with clause 4 of the
# Apache Licence, version 2.0, concerning attribution. Where there
# is a contradiction between the two licences, the GPL
# takes preference.
#
# Tsim Apiak is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tsim Apiak. If not, see <http://www.gnu.org/licenses/>.
import mysql.connector as mysql
def getnavilist():
ret = []
db = mysql.connect(host="127.0.0.1", db="navi", user="navi", passwd="navi")
cur = db.cursor(dictionary=True)
cur.execute("""
SELECT *
FROM `metaWords`
WHERE partOfSpeech <> 'num.' AND partOfSpeech <> 'prefix' AND partOfSpeech <> 'affix'
ORDER BY CHAR_LENGTH(navi) DESC""")
for row in cur:
if row["infixes"] and row["infixes"] != "NULL": # yeah seriously
ret.append({"id": row["id"], "navi": row["navi"].replace("+", "").replace("-", ""), "infix": row["infixes"].lower(), "type": row["partOfSpeech"]})
else:
ret.append({"id": row["id"], "navi": row["navi"].replace("+", "").replace("-", ""), "infix": row["navi"].replace("+", "").replace("-", "").lower(), "type": row["partOfSpeech"]})
cur.close()
db.close()
return ret
def getaffixlists():
ret = ([], [], [])
db = mysql.connect(host="127.0.0.1", db="navi", user="navi", passwd="navi")
cur = db.cursor(dictionary=True)
cur.execute("""
SELECT *
FROM `metaInfixes`
ORDER BY CHAR_LENGTH(navi) DESC""")
for row in cur:
endfix = False
if row["navi"] and row["navi"][0] == "-":
ret[2].append({"id": row["id"], "navi": row["navi"].replace("-", ""), "gloss": row["shorthand"].upper()})
endfix = True
if row["navi"] and row["navi"][-1] in ("-", "+"):
ret[0].append({"id": row["id"], "navi": row["navi"].replace("-", "").replace("+", ""), "gloss": row["shorthand"].upper()})
endfix = True
if not endfix:
if not row["position"] or row["position"] == "NULL":
# not actually an affix
continue
ret[1].append({"id": row["id"], "navi": row["navi"], "gloss": row["shorthand"].upper(), "position": int(row["position"])})
cur.close()
db.close()
for subret in ret:
subret.sort(key=lambda x: len(x["navi"]), reverse=True)
return ret
def translate(wid, language):
ret = None
db = mysql.connect(host="127.0.0.1", db="navi", user="navi", passwd="navi")
cur = db.cursor(dictionary=True)
cur.execute("""
SELECT *
FROM `localizedWords`
WHERE id = %s AND languageCode = %s""", (wid, language))
for row in cur:
ret = row["localized"]
break
if ret == None:
return u"ERROR: WORD NOT LOCALISED"
db.close()
return ret