Example #1
0
def getAcommodation(graph):
    print 'im getting your hotel preferences from graph'
    data = AcommodationRequestMessage.from_graph(graph)
    responseObj = contactWithHotelProvider(data.firstDay, data.lastDay,
                                           data.city, data.maxPrice)
    if responseObj.price > 0:
        dataContent = build_message(
            responseObj.to_graph(), FIPAACLPerformatives.AGREE,
            Ontologies.SEND_ACCOMMODATION_RESPONSE).serialize(format='xml')
    else:
        dataContent = build_message(
            responseObj.to_graph(), FIPAACLPerformatives.FAILURE,
            Ontologies.SEND_ACCOMMODATION_RESPONSE).serialize(format='xml')
    return dataContent
Example #2
0
def askPaymentData(vuelos, hotel):
    print 'Introduce a continuacion la informacion para realizar el pago:'
    print '\nNombre del titular de la tarjeta:'
    name = raw_input("")
    print '\nNumero de tarjeta:'
    card_num = raw_input("")
    print '\nProcesando el pago...'
    payURL = disIP.payment_IP + str(Constants.PORT_APayment) + "/comm"
    hotelPrice = hotel.price
    flightPrice = vuelos.price
    try:
        defFlightPrice = flightPrice.replace("EUR", '')
        amountHotel = float(hotelPrice)
        amountFlight = float(defFlightPrice)
        amount = amountHotel + amountFlight
    except ValueError:
        print "No se ha podido hacer el parse a float"
        return
    messageData = PaymentRequestMessage(random.randint(1, 2000), name,
                                        card_num, amount)
    gra = messageData.to_graph()
    dataContent = build_message(gra, FIPAACLPerformatives.REQUEST, Ontologies.SEND_PAYMENT_REQUEST)\
        .serialize(format='xml')
    resp = requests.post(payURL, data=dataContent)
    processPaymentResult(resp, vuelos, hotel)
    return
Example #3
0
def askForActivities(firstDay, lastDay, location, type):
    city = CodeToCityLocation(location)
    activities_url = disIP.activities_IP + str(
        Constants.PORT_AActivities) + "/comm"
    messageData = ActivitiesRequestMessage(random.randint(1, 2000), firstDay,
                                           lastDay, 200, city, type)
    gra = messageData.to_graph()
    dataContent = build_message(
        gra, FIPAACLPerformatives.REQUEST,
        Ontologies.SEND_ACTIVITIES_REQUEST).serialize(format='xml')
    resp = requests.post(activities_url, data=dataContent)
    return resp
Example #4
0
def askHotelData(maxPrice, initDate, finDate, travelCity):
    messageData = AcommodationRequestMessage(random.randint(1, 2000), initDate,
                                             finDate, maxPrice, travelCity)
    gra = messageData.to_graph()
    dataContent = build_message(
        gra, FIPAACLPerformatives.REQUEST,
        Ontologies.SEND_ACCOMMODATION_REQUEST).serialize(format='xml')

    acommURL = disIP.acommodation_IP + str(
        Constants.PORT_AAcommodation) + "/comm"
    resp = requests.post(acommURL, data=dataContent)

    return resp
Example #5
0
def directToAct(location, type):
    city = CodeToCityLocation(location)
    activities_url = Constants.LocalhostUrl + str(
        Constants.PORT_AActivities) + "/comm"
    messageData = ActivitiesRequestMessage(random.randint(1, 2000),
                                           date(2017, 7, 1), date(2017, 7, 3),
                                           200, city, type)
    gra = messageData.to_graph()
    dataContent = build_message(
        gra, FIPAACLPerformatives.REQUEST,
        Ontologies.SEND_ACTIVITIES_REQUEST).serialize(format='xml')
    resp = requests.post(activities_url, data=dataContent)
    processActivitiesResult(resp)
    print "Gracies per confiar en nosaltres, disfruti del plan :)"
    return
Example #6
0
def askFlightsData(maxPrice, initDate, finalDate, departureAirport,
                   arrivalAirport):

    flights_url = disIP.flights_IP + str(Constants.PORT_AFlights) + "/comm"

    messageDataGo = FlightRequestMessage(random.randint(1, 2000), maxPrice,
                                         initDate, finalDate, departureAirport,
                                         arrivalAirport)
    gra = messageDataGo.to_graph()
    dataContent = build_message(
        gra, FIPAACLPerformatives.REQUEST,
        Ontologies.SEND_FLIGHT_REQUEST).serialize(format='xml')

    resp = requests.post(flights_url, data=dataContent)

    return resp
Example #7
0
def processActivitiesPlan(planList):
    responseObj = ActivitiesResponseMessage(random.randint(1, 2000), planList)
    # TO-ASK: Cal ontologia de resposta tambe??? O amb performativa ja n'hi ha prou?
    dataContent = build_message(responseObj.to_graph(), FIPAACLPerformatives.AGREE,
                                Ontologies.SEND_ACTIVITIES_RESPONSE).serialize(format='xml')
    return dataContent
Example #8
0
def processPaymentResponse(resp):
    response = PaymentResponseMessage(resp.name, resp.card, resp.amount)
    dataContent = build_message(
        response.to_graph(), FIPAACLPerformatives.AGREE,
        Ontologies.SEND_PAYMENT_RESPONSE).serialize(format='xml')
    return dataContent
Example #9
0
def getFlights(graph):
    print 'im in get flights from graph'

    data = FlightRequestMessage.from_graph(graph)

    print 'data obtained: ', data
    print 'initDate: ', data.firstDay
    print 'lastDay: ', data.lastDay
    print 'maxPrice: ', data.maxPrice
    print 'departureAirport: ', data.departureAirport
    print 'arrivalAirport: ', data.arrivalAirport

    print "EUR" + str(data.maxPrice)

    #Request google flights

    code = {
        "request": {
            "slice": [{
                "origin": data.departureAirport,
                "destination": data.arrivalAirport,
                "date": data.firstDay.strftime("%Y-%m-%d")
            }, {
                "origin": data.arrivalAirport,
                "destination": data.departureAirport,
                "date": data.lastDay.strftime("%Y-%m-%d")
            }],
            "passengers": {
                "adultCount": 1,
                "infantInLapCount": 0,
                "infantInSeatCount": 0,
                "childCount": 0,
                "seniorCount": 0
            },
            "solutions":
            1,
            "maxPrice":
            "EUR" + str(data.maxPrice),
            "saleCountry":
            "ES",
            "refundable":
            "false"
        }
    }

    r = requests.post(QPX_END_POINT,
                      params={'key': QPX_API_KEY},
                      data=json.dumps(code),
                      headers=headers)
    result = r.json()

    if 'tripOption' in result['trips']:
        for trip in result['trips']['tripOption']:
            price = trip['pricing'][0]['saleTotal']

            idflightgo = trip['slice'][0]['segment'][0]['flight']['number']
            companygo = trip['slice'][0]['segment'][0]['flight']['carrier']
            departurehourgo = trip['slice'][0]['segment'][0]['leg'][0][
                'departureTime']
            arrivalhourgo = trip['slice'][0]['segment'][0]['leg'][0][
                'arrivalTime']

            idflightreturn = trip['slice'][1]['segment'][0]['flight']['number']
            companyreturn = trip['slice'][1]['segment'][0]['flight']['carrier']
            departurehourreturn = trip['slice'][1]['segment'][0]['leg'][0][
                'departureTime']
            arrivalhourreturn = trip['slice'][1]['segment'][0]['leg'][0][
                'arrivalTime']

        responseObj = FlightResponseMessage(data.uuid, price, idflightgo,
                                            companygo, departurehourgo,
                                            arrivalhourgo, idflightreturn,
                                            companyreturn, departurehourreturn,
                                            arrivalhourreturn)
        dataContent = build_message(
            responseObj.to_graph(), FIPAACLPerformatives.AGREE,
            Ontologies.SEND_ACTIVITIES_RESPONSE).serialize(format='xml')
        return dataContent

    else:
        responseObj = FlightResponseMessage(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        dataContent = build_message(
            responseObj.to_graph(), FIPAACLPerformatives.DISCONFIRM,
            Ontologies.SEND_ACTIVITIES_RESPONSE).serialize(format='xml')
        return dataContent