示例#1
0
def add(user_id,content,link=None,private=False,pics=None):
    from model import work
    from model import author
    infos = parse_content(content)
    pieces = db.select("piece",where="content=$content",vars={
        "content":infos["content"]
    })

    author_name = infos["author"]
    work_title = infos["work"]

    private = private and 1 or 0

    piece_id = None
    if not pieces:
        if infos["author"]:
            # return author_id
            infos["author"] = author.add(author_name)

        if infos["work"]:
            # return work_id
            infos["work"] = work.add(work_title)
        piece_id = db.insert("piece",content=infos["content"],author=infos["author"],work=infos["work"],user=user_id,addtime=datetime.now(),link=link,private=private,pics=pics)
    else:
        piece_id = pieces[0]["id"]

    fav.add(user_id=user_id,piece_id=piece_id)

    return piece_id
示例#2
0
def add(user_id, content, link=None, private=False, pics=None):
    from model import work
    from model import author
    infos = parse_content(content)
    pieces = db.select("piece",
                       where="content=$content",
                       vars={"content": infos["content"]})

    author_name = infos["author"]
    work_title = infos["work"]

    private = private and 1 or 0

    piece_id = None
    if not pieces:
        if infos["author"]:
            # return author_id
            infos["author"] = author.add(author_name)

        if infos["work"]:
            # return work_id
            infos["work"] = work.add(work_title)
        piece_id = db.insert("piece",
                             content=infos["content"],
                             author=infos["author"],
                             work=infos["work"],
                             user=user_id,
                             addtime=datetime.now(),
                             link=link,
                             private=private,
                             pics=pics)
    else:
        piece_id = pieces[0]["id"]

    fav.add(user_id=user_id, piece_id=piece_id)

    return piece_id
from model import piece
from model import work
from model import author
from config.setting import db

pieces = piece.get_all()
for p in pieces:
    data = piece.parse_content(p.content)
    print data
    author_name = data["author"]
    work_title = data["work"]

    if p["author"]:
        data["author"] = p["author"]
    elif data["author"]:
        # return author_id
        data["author"] = author.add(author_name)
    
    if p["work"]:
        data["work"] = p["work"]
    elif data["work"]:
        # return work_id
        data["work"] = work.add(work_title)

    db.update("piece",where="id=$id",vars=p,**data)
示例#4
0
from model import author
from config.setting import db

pieces = piece.get_all()
for p in pieces:
    data = piece.parse_content(p.content)

    author_name = data["author"]
    work_title = data["work"]

    if p["author"]:
        data["author"] = p["author"]
    elif data["author"]:
        # return author_id
        data["author"] = author.add(author_name)

    if p["work"]:
        data["work"] = p["work"]
    elif data["work"]:
        # return work_id
        data["work"] = work.add(work_title)

    # if author_name or work_title:
    #     # print p.content
    #     print "origin:\t\t" + p.content
    #     print "content:\t" + data["content"]
    #     print "author:\t\t" + (author_name and author_name or "None")
    #     print "work:\t\t" + (work_title and work_title or "None")
    #     print ""

    db.update("piece", where="id=$id", vars=p, **data)