Skip to content

Commit 43fa717

Browse files
authored
Add folder with code samples (#64)
* add code samples * update travis for code samples * raise error when error * raise error for all examples and update travis to run them all * remove unecessary prints and show only error messages * run diff scripts depending on branch * change travis script * update travis * fix name in script * fix scriopt * choose five examples to run * change examples to run when push and update hotel search * test all samples * revert travis sript following the defined exec rules * rename samples folder to examples and update dependancies * wait between api calls travis * test all files * increase sleep time in travis * delete trip parser * revert sleep time * test to run travis in one version * test updated settings * bring back to travis all python versions we test * travis settings max_num_builds * minor update * run examples only for python 3.6.3 * print run * test py versions * test * fix typo in script * test py versions * test * fix typo * revert examples to defined rules * remove run files in background
1 parent 84b1447 commit 43fa717

File tree

22 files changed

+322
-1
lines changed

22 files changed

+322
-1
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ branches:
1212
before_install:
1313
- pip install virtualenv==15.2.0
1414
- pip install tox-travis
15-
script: tox
15+
script:
16+
- tox
17+
- pip install -e .
18+
- if [[ $TRAVIS_PYTHON_VERSION == '3.6.3' ]]; then bash .travis_script.sh; fi
19+
1620
before_deploy:
1721
- pip install -e .
1822
- make docs

.travis_script.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if [[ $TRAVIS_EVENT_TYPE == "pull_request" && $TRAVIS_PULL_REQUEST_BRANCH != "master" ]] ; then
2+
python examples/hotel_search/hotel_search.py
3+
python examples/flight_choice_prediction/flight_choice_prediction.py
4+
python examples/flight_offers_search/flight_offers_search.py
5+
python examples/hotel_ratings/hotel_ratings.py
6+
python examples/points_of_interest/points_of_interest.py
7+
fi
8+
if [[ $TRAVIS_EVENT_TYPE == "push" && $TRAVIS_BRANCH == "master" ]] ; then
9+
for folder in examples/*/ ; do
10+
for file in "$folder"/* ; do
11+
if [[ $file == *.py ]]
12+
then
13+
python "$file"
14+
fi
15+
done
16+
done
17+
fi
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from amadeus import Client, ResponseError
2+
3+
amadeus = Client()
4+
5+
try:
6+
'''
7+
Generates a photo with mountain
8+
'''
9+
response = amadeus.media.files.generated_photos.get(category='MOUNTAIN')
10+
try:
11+
import urllib.request
12+
urllib.request.urlretrieve(response.data['attachmentUri'], 'generated_image.png')
13+
except ImportError:
14+
import urllib
15+
urllib.urlretrieve(response.data['attachmentUri'], 'generated_image.jpg')
16+
17+
print(response.data)
18+
except ResponseError as error:
19+
print(error)
20+
raise error
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from amadeus import Client, ResponseError
2+
3+
amadeus = Client()
4+
5+
try:
6+
'''
7+
What's the airline name for the IATA code BA?
8+
'''
9+
response = amadeus.reference_data.airlines.get(airlineCodes='BA')
10+
# print(response.data)
11+
except ResponseError as error:
12+
print(error)
13+
raise error
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from amadeus import Client, ResponseError
2+
from amadeus import Location
3+
4+
amadeus = Client()
5+
6+
try:
7+
'''
8+
Which cities or airports start with 'r'?
9+
'''
10+
response = amadeus.reference_data.locations.get(keyword='r',
11+
subType=Location.ANY)
12+
# print(response.data)
13+
except ResponseError as error:
14+
print(error)
15+
raise error
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from amadeus import Client, ResponseError
2+
3+
amadeus = Client()
4+
5+
try:
6+
'''
7+
What relevant airports are there around a specific location?
8+
'''
9+
response = amadeus.reference_data.locations.airports.get(longitude=49.000, latitude=2.55)
10+
# print(response.data)
11+
except ResponseError as error:
12+
print(error)
13+
raise error
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from amadeus import Client, ResponseError
2+
3+
amadeus = Client()
4+
5+
try:
6+
'''
7+
Will there be a delay in the JFK airport on the 1st of September?
8+
'''
9+
response = amadeus.airport.predictions.on_time.get(airportCode='JFK', date='2020-09-01')
10+
# print(response.data)
11+
except ResponseError as error:
12+
print(error)
13+
raise error
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from amadeus import Client, ResponseError
2+
3+
amadeus = Client()
4+
5+
try:
6+
'''
7+
What were the busiest months for Madrid in 2017?
8+
'''
9+
response = amadeus.travel.analytics.air_traffic.busiest_period.get(cityCode='MAD', period='2017', direction='ARRIVING')
10+
# print(response.data)
11+
except ResponseError as error:
12+
print(error)
13+
raise error
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from amadeus import Client, ResponseError
2+
3+
amadeus = Client()
4+
5+
try:
6+
'''
7+
Find cheapest dates from Madrid to London
8+
'''
9+
response = amadeus.shopping.flight_dates.get(origin='MAD', destination='LON')
10+
# print(response.data)
11+
except ResponseError as error:
12+
print(error)
13+
raise error
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from amadeus import Client, ResponseError
2+
3+
amadeus = Client()
4+
5+
try:
6+
'''
7+
What is the URL to my online check-in?
8+
'''
9+
response = amadeus.reference_data.urls.checkin_links.get(airlineCode='BA')
10+
# print(response.data)
11+
except ResponseError as error:
12+
print(error)
13+
raise error

0 commit comments

Comments
 (0)