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}
def makedictjson(user): res = ops.makeDict(request.forms.url, request.forms.template, request.forms.title, "", user["email"]) return {"success": res}
#!/usr/bin/env python3 import sys, os, os.path if len(sys.argv) < 3 or len(sys.argv) > 5: print("Usage: ./add.py PATH_TO_DICTIONARY.sqlite EMAIL [TITLE [BLURB]]") print( "This script adds an existing dictionary SQLITE DB file to the main Lexonomy database and grants all access rights for user identified by EMAIL" ) sys.exit(1) srcDB = os.path.abspath(sys.argv[1]) sys.path.insert( 0, os.path.split(os.path.dirname(os.path.abspath(sys.argv[0])))[0]) os.chdir("..") from ops import makeDict title = "" blurb = "" if len(sys.argv) > 3: title = sys.argv[3] if len(sys.argv) > 4: blurb = sys.argv[4] dictID, sqlite_ext = os.path.splitext(os.path.basename(srcDB)) makeDict(dictID, srcDB, title, blurb, sys.argv[2])