Ejemplo n.º 1
0
def pushapi():
    data = json.loads(request.body.getvalue().decode('utf-8'))
    user = ops.verifyUserApiKey(data["email"], data["apikey"])
    if not user["valid"]:
        return {"success": False}
    else:
        if data["command"] == "makeDict":
            dictID = ops.suggestDictId()
            dictTitle = re.sub(r"^\s+", "", data["dictTitle"])
            if dictTitle == "":
                dictTitle = dictID
            dictBlurb = data["dictBlurb"]
            poses = data["poses"]
            labels = data["labels"]
            res = ops.makeDict(dictID, "push", dictTitle, dictBlurb,
                               user["email"])
            if not res:
                return {"success": False}
            else:
                dictDB = ops.getDB(dictID)
                configs = ops.readDictConfigs(dictDB)
                if configs["xema"]["elements"].get("partOfSpeech"):
                    for pos in poses:
                        configs["xema"]["elements"]["partOfSpeech"][
                            "values"].append({
                                "value": pos,
                                "caption": ""
                            })
                if configs["xema"]["elements"].get("collocatePartOfSpeech"):
                    for pos in poses:
                        configs["xema"]["elements"]["collocatePartOfSpeech"][
                            "values"].append({
                                "value": pos,
                                "caption": ""
                            })
                if configs["xema"]["elements"].get("label"):
                    for label in labels:
                        configs["xema"]["elements"]["label"]["values"].append({
                            "value":
                            label,
                            "caption":
                            ""
                        })
                ops.updateDictConfig(dictDB, dictID, "xema", configs["xema"])
                return {"success": True, "dictID": dictID}
        elif data["command"] == "listDicts":
            dicts = ops.getDictsByUser(user["email"])
            return {"entries": dicts, "success": True}
        elif data["command"] == "createEntries":
            dictID = data["dictID"]
            entryXmls = data["entryXmls"]
            dictDB = ops.getDB(dictID)
            configs = ops.readDictConfigs(dictDB)
            for entry in entryXmls:
                ops.createEntry(dictDB, configs, None, entry, user["email"],
                                {"apikey": data["apikey"]})
            return {"success": True}
        else:
            return {"success": False}
Ejemplo n.º 2
0
def configupdate(dictID, user, dictDB, configs):
    adjustedJson, resaveNeeded = ops.updateDictConfig(
        dictDB, dictID, request.forms.id, json.loads(request.forms.content))
    if resaveNeeded:
        configs = ops.readDictConfigs(dictDB)
        ops.resave(dictDB, dictID, configs)
    return {"success": True, "id": request.forms.id, "content": adjustedJson}
Ejemplo n.º 3
0
def publicrandom(dictID):
    if not ops.dictExists(dictID):
        return redirect("/")
    dictDB = ops.getDB(dictID)
    configs = ops.readDictConfigs(dictDB)
    if not configs["publico"]["public"]:
        return {"more": False, "entries": []}
    res = ops.readRandoms(dictDB)
    return res
Ejemplo n.º 4
0
def ontolex(dictID, doctype):
    data = json.loads(request.body.getvalue().decode('utf-8'))
    if not data.get("email") or not data.get("apikey"):
        return {"success": False, "message": "missing email or api key"}
    user = ops.verifyUserApiKey(data["email"], data["apikey"])
    if not user["valid"]:
        return {"success": False}
    else:
        if data.get("search"):
            search = data["search"]
        else:
            search = ""
        dictDB = ops.getDB(dictID)
        configs = ops.readDictConfigs(dictDB)
        dictAccess = configs["users"].get(
            user["email"]) or user["email"] in siteconfig["admins"]
        if not dictAccess:
            return {"success": False}
        else:
            response.headers['Content-Type'] = "text/plain; charset=utf-8"
            return ops.listOntolexEntries(dictDB, dictID, configs, doctype,
                                          search)
Ejemplo n.º 5
0
        entryCount = 0
        saxParser = xml.sax.parseString(xmldata, handlerFirst())
    else:
        if entryTag == "":
            print("Not possible to detect element name for entry, please fix errors:")
            print(e, file=sys.stderr)
            sys.exit()

# second pass, we know what the entry is and can import that
import re

entryCount = len(re.findall('<'+entryTag+'[ >]', xmldata))
entryInserted = 0
print("Detected %d entries in '%s' element" % (entryCount, entryTag))

configs = ops.readDictConfigs(db)
needs_refac = 1 if len(list(configs["subbing"].keys())) > 0 else 0
needs_resave = 1 if configs["searchability"].get("searchableElements") and len(configs["searchability"].get("searchableElements")) > 0 else 0

re_entry = re.compile(r'<'+entryTag+'[^>]*>.*?</'+entryTag+'>', re.MULTILINE|re.DOTALL|re.UNICODE)
for entry in re.findall(re_entry, xmldata):
    skip = False
    try:
        xml.sax.parseString(entry, xml.sax.handler.ContentHandler())
    except xml.sax._exceptions.SAXParseException as e:
        skip = True
        print("Skipping entry, XML parsing error: " + str(e), file=sys.stderr)
        print("Skipping entry, XML parsing error: " + str(e))
        print("Entry with error: " + entry, file=sys.stderr)
        entryInserted += 1
    if not skip:
Ejemplo n.º 6
0
#!/usr/bin/python3

import os
import os.path
import sqlite3
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import ops

if len(sys.argv) < 2:
    print("Usage: ./xml2ontolex DB.sqlite")
    sys.exit()

dbname = sys.argv[1]
dictID = os.path.basename(dbname).replace(".sqlite", "")
dictDB = sqlite3.connect(dbname)
dictDB.row_factory = sqlite3.Row
configs = ops.readDictConfigs(dictDB)

for line in ops.listOntolexEntries(dictDB, dictID, configs, configs["xema"]["root"], ""):
    sys.stdout.write(line)