Ejemplo n.º 1
0
def handle_response(serialized_msg):
    response = price_service_pb2.PsResponse()
    response.ParseFromString(serialized_msg)
    # text_format.PrintMessage(response, sys.stdout)
    # return response
    # response_str = text_format.MessageToString(response)
    return pb2dict(response)
Ejemplo n.º 2
0
def handle_response(serialized_msg, show_type):
    response = price_service_pb2.PsResponse()
    response.ParseFromString(serialized_msg)
    # text_format.PrintMessage(response, sys.stdout)
    # return response
    # response_str = text_format.MessageToString(response)
   
    if  show_type == "1":
        # return pb2json(response)
        return json.dumps(json.loads(pb2json(response)), indent=4, sort_keys=False, ensure_ascii=False)
    else:
        return pb2dict(response)
Ejemplo n.º 3
0
def handle_response(serialized_msg, in_param_dict):
    try:
        response = price_service_pb2.PsResponse()
        response.ParseFromString(serialized_msg)
    except Exception as e:
        print "fail", len(serialized_msg)

    if response.list_response and response.list_response.list_hotel:
        # for lh in response.list_response.list_hotel:
        #     # 1. sold out
        #     if lh.booking_status == 1:
        #         print "%d_%s_%d" % (lh.base_hotel_id, in_param_dict["month"], 1)
        #     else:
        #         print "%d_%s_%d" % (lh.base_hotel_id, in_param_dict["month"], 0)
        print "success", len(serialized_msg)
Ejemplo n.º 4
0
def handle_response(serialized_msg, in_param_dict):
    try:
        response = price_service_pb2.PsResponse()
        response.ParseFromString(serialized_msg)
    except Exception as e:
        return "fail"

    if response.list_response and response.list_response.list_hotel:
        for lh in response.list_response.list_hotel:
            # 1. sold out
            if lh.booking_status == 1:
                print "%d_%s_%d" % (lh.base_hotel_id, in_param_dict["month"],
                                    1)
            else:
                print "%d_%s_%d" % (lh.base_hotel_id, in_param_dict["month"],
                                    0)
                # # 2. three days ago
                # if int(time.time()) - lh.crawl_time >= 259200:
                #     print "%d_%s_%d" % (lh.base_hotel_id, in_param_dict["month"], 2)
                # else:
                #     # 3. has price
                #     print "%d_%s_%d" % (lh.base_hotel_id, in_param_dict["month"], 0)
    return "success"