示例#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 addShelf():
    try:
        open_id = request.json['open_id']
        author_name = request.json['author_name']
        book_name = request.json['book_name']
        chapter_url = request.json['chapter_url']
        if not open_id and not author_name and not book_name and not chapter_url:
            return jsonify({'code': '9999', 'message': '新增数据失败:参数值不能为空'})

        db = Db()
        sql = 'insert into gysw_shelf (`open_id`, `author_name`, `book_name`, `chapter_url`) values (%s, %s, %s, %s)'
        db.insertOne(sql, (open_id, author_name, book_name, chapter_url))
        db.close()
        return jsonify({'code': '0000', 'message': '新增数据成功'})
    except:
        return jsonify({'code': '9999', 'message': '新增数据失败'})