예제 #1
0
def addSearch():
    try:
        open_id = request.json['open_id']
        keyword = request.json['keyword']
        if not open_id and not keyword:
            return jsonify({'code': '9999', 'message': '新增数据失败:参数值不能为空'})
        db = Db()
        # 取数据
        result = db.selectAll(
            'select * from gysw_search where keyword = "%s" and open_id = "%s"'
            % (keyword, open_id))
        if not result or len(result) == 0:
            print('新增...')
            # 没有,新增
            sql = 'insert into gysw_search (`open_id`, `keyword`, `last_update_at`) values (%s, %s, %s)'
            localtime = time.localtime(time.time())
            db.insertOne(sql, (open_id, keyword, localtime))
        else:
            print('修改...')
            # 修改,次数 +1
            current = result[0]
            times = current['times'] + 1
            db.updateOne(
                'update gysw_search set times = %d where open_id = "%s" and keyword = "%s"'
                % (times, open_id, keyword))

        db.close()
        return jsonify({'code': '0000', 'message': '新增数据成功'})
    except Exception as e:
        print(e)
        return jsonify({'code': '9999', 'message': '新增数据失败'})
예제 #2
0
def editShelf(id):
    chapter_url = request.json['chapter_url']
    try:
        db = Db()
        db.updateOne('update gysw_shelf set chapter_url = "%s" where id = %s' %
                     (chapter_url, id))
        db.close()
        return jsonify({'code': '0000', 'message': '修改数据成功'})
    except:
        return jsonify({'code': '9999', 'message': '修改数据失败'})