Esempio n. 1
0
    def query(self, dateFrom, dateTo, frm, to, persons):
        flights_cache_service = FlightsCache(self.key)
        result = flights_cache_service.get_cheapest_quotes(
            market='UK',
            currency='USD',
            locale='en-US',
            originplace=frm,
            destinationplace=to,
            outbounddate=dateFrom.strftime("%Y-%m-%d"),
            #inbounddate=dateTo.strftime("%Y-%m-%d"),
            adults=persons).parsed

        carriers = dict([(carr['CarrierId'], carr['Name'])
                         for carr in result['Carriers']])

        rv = dict(dateFrom=dateFrom,
                  dateTo=dateTo,
                  frm=frm,
                  to=to,
                  persons=persons,
                  price=result['Quotes'][0]['MinPrice'],
                  currency=result['Currencies'][0]['Code'],
                  carrier=carriers[result['Quotes'][0]['OutboundLeg']
                                   ['CarrierIds'][0]],
                  timestamp=datetime.datetime.now())

        print rv

        return rv
Esempio n. 2
0
def skyscanner(msg,bot,update):

	if((msg.find("flight") == -1) and (msg.find("to fly") == -1) and (msg.find("fly to") == -1) and (msg.find("fly from") == -1) and (msg.find("go to") == -1)):
		update.message.reply_text("Are you asking for a flight?")

	else:
		try:
			index_to = msg.rfind("to ")
			index_from = msg.rfind("from ")
			msg = msg + " " # Som una mica ganduls i no volem que el find(" ") retorni -1 si es l'ultima paraula

			flights_cache_service = FlightsCache('ha306082955374085267757354385037')
			if (index_to) != -1:
				to = msg[index_to + 3:]
				to = to[:to.find(" ")]
				

			if (index_from) != -1:
				from_ = msg[index_from + 5:]
				from_ = from_[:from_.find(" ")]
				

			to = cityDecoder(to)
			from_ = cityDecoder(from_)		

			result = flights_cache_service.get_cheapest_quotes(
				market='ES',
				currency='eur',
				locale='en-GB',
				originplace=from_["Places"][0]["PlaceId"],
				destinationplace=to["Places"][0]["PlaceId"],
				outbounddate='anytime',
				adults=1
				).parsed

			carrierID = result["Quotes"][0]["OutboundLeg"]["CarrierIds"][0]
			aeroSortida = result["Quotes"][0]["OutboundLeg"]["OriginId"]
			aeroArribada = result["Quotes"][0]["OutboundLeg"]["DestinationId"]
			departureDate = result["Quotes"][0]["OutboundLeg"]["DepartureDate"]

			carrierDic = {}
			for carrier in result["Carriers"]:
				carrierDic[carrier["CarrierId"]] = carrier["Name"];

			placesDic = {}
			for place in result["Places"]:
				placesDic[place["PlaceId"]] = place
				place.pop('PlaceId', None)

			price, url = getLink(from_["Places"][0]["PlaceId"], to["Places"][0]["PlaceId"], departureDate[:10])

			update.message.reply_text("Departure from "+placesDic[aeroSortida]["Name"]+
				" Airport to "+placesDic[aeroArribada]["Name"]+" Airport, with departure date: " + departureDate[:10] + " from "+str(format(price, '.0f')) + " " +result["Currencies"][0]["Symbol"]+".\n\n You can book it from here: " + url)	

		except Exception as e:
			print(e)
			update.message.reply_text("Some data seems wrong, have you indicated an origin and a destination?")
    def test_get_cheapest_quotes_xml(self):
        flights_cache_service = FlightsCache(self.api_key, response_format='xml')
        self.result = flights_cache_service.get_cheapest_quotes(
            market='DE',
            currency='EUR',
            locale='de-DE',
            originplace='TXL',
            destinationplace='LHR',
            outbounddate=self.outbound,
            inbounddate=self.inbound).parsed

        self.assertIsNotNone(self.result.find('./Quotes'))
        self.assertTrue(len(self.result.findall('./Quotes/QuoteDto')) > 0)
    def test_get_cheapest_quotes_json(self):
        flights_cache_service = FlightsCache(self.api_key, response_format='json')
        self.result = flights_cache_service.get_cheapest_quotes(
            market='GB',
            currency='GBP',
            locale='en-GB',
            originplace='SIN',
            destinationplace='KUL',
            outbounddate=self.outbound,
            inbounddate=self.inbound).parsed

        self.assertTrue('Quotes' in self.result)
        self.assertTrue(len(self.result['Quotes']) > 0)
    def test_get_cheapest_quotes(self):
        flights_cache_service = FlightsCache(self.api_key)
        self.result = flights_cache_service.get_cheapest_quotes(
            country='UK',
            currency='GBP',
            locale='en-GB',
            originplace='SIN-sky',
            destinationplace='KUL-sky',
            outbounddate=self.outbound,
            inbounddate=self.inbound)

        self.assertTrue('Quotes' in self.result)
        self.assertTrue(len(self.result['Quotes']) > 0)
    def test_get_cheapest_quotes_xml(self):
        flights_cache_service = FlightsCache(self.api_key,
                                             response_format='xml')
        self.result = flights_cache_service.get_cheapest_quotes(
            market='DE',
            currency='EUR',
            locale='de-DE',
            originplace='TXL',
            destinationplace='LHR',
            outbounddate=self.outbound,
            inbounddate=self.inbound).parsed

        self.assertTrue(None != self.result.find('./Quotes'))
        self.assertTrue(len(self.result.findall('./Quotes/QuoteDto')) > 0)
    def test_get_cheapest_quotes_json(self):
        flights_cache_service = FlightsCache(self.api_key,
                                             response_format='json')
        self.result = flights_cache_service.get_cheapest_quotes(
            market='GB',
            currency='GBP',
            locale='en-GB',
            originplace='SIN',
            destinationplace='KUL',
            outbounddate=self.outbound,
            inbounddate=self.inbound).parsed

        self.assertTrue('Quotes' in self.result)
        self.assertTrue(len(self.result['Quotes']) > 0)
    def test_get_cheapest_quotes_xml(self):
        flights_cache_service = FlightsCache(self.api_key, response_format="xml")
        self.result = flights_cache_service.get_cheapest_quotes(
            market="DE",
            currency="EUR",
            locale="de-DE",
            originplace="TXL",
            destinationplace="LHR",
            outbounddate=self.outbound,
            inbounddate=self.inbound,
        ).parsed

        self.assertTrue(None != self.result.find("./Quotes"))
        self.assertTrue(len(self.result.findall("./Quotes/QuoteDto")) > 0)
    def test_get_cheapest_quotes_json(self):
        flights_cache_service = FlightsCache(self.api_key, response_format="json")
        self.result = flights_cache_service.get_cheapest_quotes(
            market="GB",
            currency="GBP",
            locale="en-GB",
            originplace="SIN",
            destinationplace="KUL",
            outbounddate=self.outbound,
            inbounddate=self.inbound,
        ).parsed

        self.assertTrue("Quotes" in self.result)
        self.assertTrue(len(self.result["Quotes"]) > 0)
Esempio n. 10
0
def query_handler():

    # api_query = requests.post('http://partners.api.skyscanner.net/apiservices/pricing/v1.0').content
    flights_cache_service = FlightsCache(apikey)
    result = flights_cache_service.get_cheapest_quotes(
        market='UK',
        country='UK',
        currency='GBP',
        locale='en-GB',
        originplace='SIN-sky',
        destinationplace='KUL-sky',
        outbounddate='2017-05-28',
        inbounddate='2017-05-31',
        adults=1).parsed
    # return requests.get('http://partners.api.skyscanner.net/apiservices/pricing/v1.0/{my_id}?apiKey={apikey}').content
    # form_data = requests.form
    # print form_data['name']
    # requests.form()
    return render_template("results.html", results=result)
Esempio n. 11
0
def get_data():
    return render_template('Fly.html')
    return requests.post(
        'http://partners.api.skyscanner.net/apiservices/pricing/v1.0').content
    flights_cache_service = FlightsCache('<apikey>')
    result = flights_cache_service.get_cheapest_quotes(
        country='UK',
        currency='GBP',
        locale='en-GB',
        originplace='SIN-sky',
        destinationplace='KUL-sky',
        outbounddate='2017-05-28',
        inbounddate='2017-05-31',
        adults=1).parsed
    return requests.get(
        'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/{my_id}?apiKey={apikey}'
    ).content
    form_data = requests.form
    print form_data['name']
    return "All OK"
Esempio n. 12
0
 https://github.com/Skyscanner/skyscanner-python-sdk
 https://skyscanner.readthedocs.io/en/latest/index.html

:Authors: bejar
    

:Version: 

:Created on: 23/01/2017 16:38 

"""

__author__ = 'bejar'

from AgentUtil.APIKeys import SKYSCANNER_KEY

from skyscanner.skyscanner import FlightsCache

flights_cache_service = FlightsCache(SKYSCANNER_KEY)
result = flights_cache_service.get_cheapest_quotes(
    market='UK',
    currency='EUR',
    locale='es-ES',
    originplace='BCN',
    destinationplace='GVA',
    outbounddate='2017-02-02',
    inbounddate='2017-02-07').parsed

print(result)