Exemplo n.º 1
0
def searchTags(searchWord):
    searchWordList = jieba.cut_for_search(searchWord)
    res = []
    for word in searchWordList:
        res += db.query_db(
            'select chinese from tags where chinese like "%%{}%%";', word)
        res += db.query_db(
            'select chinese from tags where english like "%%{}%%";', word)

    res = [item['chinese'] for item in res]
    res = list(set(res))
    from ..tags.main import getTag
    res = [getTag(chinese) for chinese in res]
    return res
Exemplo n.º 2
0
def getPostsByTime(limit, offset=0):
    posts = db.query_db(
        'select * from posts_show where published="true" order by time desc limit {} offset {};',
        limit, offset)
    for post in posts:
        post['tags'] = formatTags(post['tags'])
    return posts
Exemplo n.º 3
0
def getRawTags():
    '''
    description:    query all tags
    input:
    output:         List - tags list
    '''
    if not hasattr(g, "tags_getRawTags"):
        g.tags_getRawTags = db.query_db('select * from tags')
    return g.tags_getRawTags
Exemplo n.º 4
0
def getTagByEnglish(english):
    '''
    description:    get the tag by english
    input:          text - tag english
    output:         dict - tag
    '''
    return db.query_db('select * from tags where english="{}"',
                       english,
                       one=True)
Exemplo n.º 5
0
def getTag(chinese):
    '''
    description:    get the tag by chinese
    input:          text - tag chinese
    output:         dict - tag
    '''
    return db.query_db('select * from tags where chinese="{}"',
                       chinese,
                       one=True)
Exemplo n.º 6
0
def getPostForEdit(url):
    '''
    description:    get the post for edit
    input:          text - url of the post
    output:         dict - post
    '''
    res = db.query_db('select * from posts_edit where url="{}";',
                      url,
                      one=True)
    return res
Exemplo n.º 7
0
def getPostsByTag(tagName):
    posts = db.query_db(
        'select * from posts_card where tags like "%%{}%%" and url in (select url from posts where published="true") order by updatetime;',
        tagName)
    res = []
    for post in posts:
        post['tags'] = formatTags(post['tags'])
        for tag in post['tags']:
            if tag['chinese'] == tagName:
                res.append(post)
                break
    return res
Exemplo n.º 8
0
def subtractTag(chinese):
    '''
    description:    tag num subtract 1
    input:          tag id(chinese)
    output:         0
    '''
    if db.exist_db("tags", {"chinese": chinese}) == True:
        cnt = db.query_db('select cnt from tags where chinese="{}"',
                          chinese,
                          one=True)['cnt']
        cnt = str(int(cnt) - 1)
        db.update_db("tags", {'cnt': cnt}, {'chinese': chinese})
        if int(cnt) <= 0:
            deleteTag(chinese)
Exemplo n.º 9
0
def getPostForShow(url):
    '''
    description:    get the post for show(post pages)
    input:          text - url of the post
    output:         dict - post
    '''
    res = db.query_db('select * from posts_show where url="{}";',
                      url,
                      one=True)
    # res.sort(key=lambda x: int(x["idx"]))

    # 2018-5-10 文章为404时,对None对象分析标签bug
    if res:
        res['tags'] = formatTags(res['tags'])
    return res
Exemplo n.º 10
0
def searchPosts(searchWord):
    searchWordList = jieba.cut_for_search(searchWord)

    queryStr = [
        'title like "%{0}%" or abstruct like "%{0}%" or raw like "%{0}%" or tags like "%{0}%"'.format(
            db.escapeChar(word))
        for word in searchWordList
    ]
    queryStr = ' or '.join(queryStr)

    queryStr = 'select * from posts_card where url in (select url from posts where ({0}) and url in(select url from posts where published="true")) order by updatetime DESC;'.format(
        queryStr)

    posts = db.query_db(queryStr)

    from ..tags.main import getTags
    tags = getTags()

    for post in posts:
        post['tags'] = [tags[tag] for tag in post['tags'].split(',')]
    return posts
Exemplo n.º 11
0
def addTag(chinese):
    '''
    description:    tag num plus 1
    input:          tag id(chinese)
    output:         0
    '''
    if db.exist_db("tags", {"chinese": chinese}) == True:
        cnt = db.query_db('select cnt from tags where chinese="{}"',
                          chinese,
                          one=True)['cnt']
        cnt = str(int(cnt) + 1)
        db.update_db("tags", {'cnt': cnt}, {'chinese': chinese})
    else:
        db.insert_db(
            "tags", {
                "chinese": chinese,
                "english": encode(chinese),
                "cnt": "1",
                "img": "",
                "class": ""
            })
    return 0
Exemplo n.º 12
0
def getPublishedPostsUrl():
    posts = db.query_db('select url from posts where published="true";')
    return posts
Exemplo n.º 13
0
def getPages():
    if not hasattr(g, "getPages"):
        res = db.query_db('select * from pages;')
        res.sort(key=lambda x: int(x["idx"]))
        g.getPages = res
    return g.getPages
Exemplo n.º 14
0
def getPostsForList():
    res = db.query_db('select * from posts_list order by time;')
    # res.sor key=lambda x: int(x["idx"]))
    return res
Exemplo n.º 15
0
def getShowGoodsOfID(_id):
    return db.query_db('select * from goods where id="{}" and show="true"', _id, one=True)
Exemplo n.º 16
0
def getAllPosts():
    posts = db.query_db('select * from posts;')
    return posts
Exemplo n.º 17
0
def getSiteConfig():
    if not hasattr(g, 'getSiteConfig'):
        res = db.query_db('select * from siteConfig')
        g.getSiteConfig = res
    return g.getSiteConfig
Exemplo n.º 18
0
def getAllComments():
    return db.query_db('select * from comments;')
Exemplo n.º 19
0
def getCommentsOfID(_id):
    return db.query_db('select * from comments where id="{}"', _id, one=True)
Exemplo n.º 20
0
def getCommentsOfUrlForShow(url):
    res = db.query_db(
        'select id,html,username,time,sendemail,ad from comments where url="{}" and show="true"',
        url)
    return res
Exemplo n.º 21
0
def getAllGoods():
    return db.query_db('select * from goods;')
Exemplo n.º 22
0
def getFriends():
    friends = db.query_db('select * from friends')
    friends.sort(key=lambda x: int(x["idx"]))
    return friends
Exemplo n.º 23
0
def getAllShowGoods():
    return db.query_db('select * from goods where show="true";')