Example #1
0
def houses_list():
    try:
        houses = store_houses().find({'owner': {"$nin": ['屋主']}})
        houses_data = HouseSchema.dump(houses, many=True)

        return houses_data
    except:
        result.write_log("critical",
                         "Failed connect to mongoDB, method: houses_list")
        return None
Example #2
0
def find_houses_by_phone_num(phone_num):
    try:
        house = store_houses().find_one({'phone_num': phone_num})
        house_data = HouseSchema.dump(house)
        return house_data

    except:
        result.write_log(
            "critical",
            "Failed connect to mongoDB, method: find_houses_by_phone_num")
        return None
Example #3
0
def after_request(response):
    resp = response.get_json()

    if resp is not None:
        code, status, description = resp["code"], resp["status"], resp[
            "description"]
        response_info = "Server response info, code: {0}, status: {1}, description: {2}"

        if code == 500:
            result.write_log('warning',
                             response_info.format(code, status, description))
        else:
            result.write_log('info',
                             response_info.format(code, status, description))

    return response
Example #4
0
def post():
    # get post data
    json_data = request.get_json()

    try:
        # input check by ma.Schema
        json_check = user_schema.load(json_data)
        # get json of server response
        result_json = result.result(200, "ping successful")[0].get_json()
        # logging post data
        result.write_log('info', "data: {}".format(json_data))
    except:
        return result.result(400, "please check your parameters")

    result_json['data'] = json_check

    return jsonify(result_json)
Example #5
0
def image():
    json_data = request.get_json()

    try:
        image_url = json_data['image']
        local_image_filename = wget.download(image_url)

        find_image_dict = find_image(test_model, local_image_filename)
        # get json of server response
        result_json = result.result(200, "ping successful")[0].get_json()
        # logging post data
        result.write_log('info', "data: {}".format(find_image_dict))

        if os.path.exists(local_image_filename):
            os.remove(local_image_filename)
    except:
        return result.result(400, "please check your parameters")

    result_json['data'] = find_image_dict
    return jsonify(result_json)
Example #6
0
def find_houses_by_owner_region(name, region):
    try:
        house = store_houses().find(
            {
                'name': name,
                'addr': {
                    '$regex': '^{}.*'.format(region)
                }
            }, {
                'name': 1,
                'phone_num': 1,
                'addr': 1
            })
        house_data = HouseSchema.dump(house, many=True)
        return house_data

    except:
        result.write_log(
            "critical",
            "Failed connect to mongoDB, method: find_houses_by_phone_num")
        return None
Example #7
0
def before_request():
    result.write_log(
        'info',
        "User requests info, path: {0}, method: {1}, ip: {2}, agent: {3}".
        format(str(request.path), str(request.method),
               str(request.remote_addr), str(request.user_agent)))
Example #8
0
def connect_collection(db_name, collection):
    result.write_log(
        "info",
        "Connect to mongoDB, host: {0}, port: {1}, db: {2}, collection: {3}".
        format(util.MONGO_HOST, util.MONGO_PORT, db_name, collection))
    return Connection()[db_name][collection]