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
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
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
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)
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)
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
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
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)
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
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
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
def getPublishedPostsUrl(): posts = db.query_db('select url from posts where published="true";') return posts
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
def getPostsForList(): res = db.query_db('select * from posts_list order by time;') # res.sor key=lambda x: int(x["idx"])) return res
def getShowGoodsOfID(_id): return db.query_db('select * from goods where id="{}" and show="true"', _id, one=True)
def getAllPosts(): posts = db.query_db('select * from posts;') return posts
def getSiteConfig(): if not hasattr(g, 'getSiteConfig'): res = db.query_db('select * from siteConfig') g.getSiteConfig = res return g.getSiteConfig
def getAllComments(): return db.query_db('select * from comments;')
def getCommentsOfID(_id): return db.query_db('select * from comments where id="{}"', _id, one=True)
def getCommentsOfUrlForShow(url): res = db.query_db( 'select id,html,username,time,sendemail,ad from comments where url="{}" and show="true"', url) return res
def getAllGoods(): return db.query_db('select * from goods;')
def getFriends(): friends = db.query_db('select * from friends') friends.sort(key=lambda x: int(x["idx"])) return friends
def getAllShowGoods(): return db.query_db('select * from goods where show="true";')