Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
http_response.read().returns('{ "data" : { "a" : 1 } }')
self.client.http = method_returning(http_response)
response = self.client._unauthenticated_request(
'GET', '/foo', {}, None
)
expect(self.client.http).to(have_been_called.once)
expect(self.response).to(equal(self.response))
with it('should catch a HTTPError'):
self.client.http = method_raising(URLError('Error'))
expect(
lambda: self.client._unauthenticated_request(
'GET', '/foo', {}, None
)
).to(raise_error(ResponseError))
with it('should log when in debug mode'):
with Stub() as http_response:
http_response.code = 200
http_response.getheaders().returns(
[('Content-Type', 'application/json')]
)
http_response.read().returns('{ "data" : { "a" : 1 } }')
self.client.http = method_returning(http_response)
self.client.logger = Spy()
self.client.log_level = 'debug'
response = self.client._unauthenticated_request(
'GET', '/foo', {}, None
)
expect(self.client.logger.debug).to(have_been_called.twice)
from amadeus import Client, ResponseError
amadeus = Client()
print('Flight Choice Prediction')
try:
'''
Find the probability of the flight MAD to NYC to be chosen
'''
result = amadeus.shopping.flight_offers.get(origin='MAD', destination='NYC',
departureDate='2020-10-01').result
response = amadeus.shopping.flight_offers.prediction.post(result)
print(response.data)
except ResponseError as error:
raise error
print('AI Generated Photos')
try:
'''
Generates a photo with mountain
'''
response = amadeus.media.files.generated_photos.get(category='MOUNTAIN')
try:
import urllib.request
urllib.request.urlretrieve(response.data['attachmentUri'], 'generated_image.png')
except ImportError:
import urllib
urllib.urlretrieve(response.data['attachmentUri'], 'generated_image.jpg')
print(response.data)
except ResponseError as error:
raise error
from amadeus import Client, ResponseError
amadeus = Client()
print('Hotel Ratings')
try:
'''
What travelers think about this hotel?
'''
response = amadeus.e_reputation.hotel_sentiments.get(hotelIds = 'ADNYCCTB')
print(response.data)
except ResponseError as error:
raise error
from amadeus import Client, ResponseError
amadeus = Client()
print('Flight Check-in Links')
try:
'''
What is the URL to my online check-in?
'''
response = amadeus.reference_data.urls.checkin_links.get(airlineCode='BA')
print(response.data)
except ResponseError as error:
raise error
from amadeus import Client, ResponseError
from amadeus import Location
amadeus = Client()
print('Airport and City Search')
try:
'''
Which cities or airports start with 'r'?
'''
response = amadeus.reference_data.locations.get(keyword='r',
subType=Location.ANY)
print(response.data)
except ResponseError as error:
raise error
from amadeus import Client, ResponseError
amadeus = Client()
print('Flight Most Booked Destinations')
try:
'''
Where were people flying to from Madrid in the August 2017?
'''
response = amadeus.travel.analytics.air_traffic.booked.get(originCityCode='MAD', period='2017-08')
print(response.data)
except ResponseError as error:
raise error
from amadeus import Client, ResponseError
amadeus = Client()
print('Aiport on Time Performance')
try:
'''
Will there be a delay in the JFK airport on the 1st of September?
'''
response = amadeus.airport.predictions.on_time.get(airportCode='JFK', date='2020-09-01')
print(response.data)
except ResponseError as error:
raise error
from amadeus import Client, ResponseError
amadeus = Client()
print('Flight Offers Search')
try:
'''
Find the cheapest flights from SYD to BKK
'''
response = amadeus.shopping.flight_offers_search.get(originLocationCode='SYD', destinationLocationCode='BKK', departureDate='2020-07-01', adults=1)
print(response.data)
except ResponseError as error:
raise error
from amadeus import Client, ResponseError
amadeus = Client()
print('Flight Most Traveled Destinations')
try:
'''
Where were people flying to from Madrid in the January 2017?
'''
response = amadeus.travel.analytics.air_traffic.traveled.get(originCityCode='MAD', period='2017-01')
print(response.data)
except ResponseError as error:
raise error