Exemplo n.º 1
0
def updateTag():
    tagIds=request.form.getlist('tags')
    # print(type(tagIds))
    # print(tagIds)
    try:
        current_user.tags=[]
        session.commit()
        for tagId in tagIds:
            # if session.query(UserTag).filter(UserTag.userId==current_user.id,UserTag.tagId==tagId).count()==0:
            # session.add(UserTag(userId=current_user.id,tagId=tagId))
            current_user.tags.append(Tag.query_one(id=tagId))
        session.commit()
        return success({})
    except Exception as e:
        # print(e)
        session.rollback()
        return error({'message':"抱歉出现错误,请发送详细内容到[email protected]"})
Exemplo n.º 2
0
import xmltodict
import sys
sys.path.append('../')
from db import Tag, Word

with open('wordbook.xml', encoding='utf8') as fd:
    doc = xmltodict.parse(fd.read())

for item in doc['wordbook']['item']:
    num = Tag.query_count(tag=item['tags'])
    if num == 0:
        tag = Tag(tag=item['tags'])
        Tag.insert(tag)
    else:
        tag = Tag.query_one(tag=item['tags'])
    wordNum = Word.query_count(word=item['word'])
    if wordNum == 0:
        word = Word(word=item['word'], explanation=item['trans'])
    else:
        continue
    word.tags.append(tag)
    Word.insert(word)