ogn-python/ogn/commands/showairport.py

27 wiersze
741 B
Python
Czysty Zwykły widok Historia

2016-05-22 05:20:29 +00:00
from manager import Manager
2017-10-03 11:31:24 +00:00
from ogn.commands.dbutils import session
from ogn.model import Airport
2016-07-14 19:14:55 +00:00
from sqlalchemy import and_, between
2017-10-03 11:31:24 +00:00
2016-05-22 05:20:29 +00:00
manager = Manager()
2016-07-14 19:14:55 +00:00
@manager.arg('country_code', help='filter by country code, eg. "de" for germany')
2016-05-22 05:20:29 +00:00
@manager.command
2016-07-14 19:14:55 +00:00
def list_all(country_code=None):
2016-05-22 05:20:29 +00:00
"""Show a list of all airports."""
2016-07-14 19:14:55 +00:00
or_args = []
if country_code is None:
or_args = [between(Airport.style, 2, 5)]
else:
or_args = [and_(between(Airport.style, 2, 5),
Airport.country_code == country_code)]
2016-05-22 05:20:29 +00:00
query = session.query(Airport) \
2016-07-14 19:14:55 +00:00
.order_by(Airport.name) \
.filter(*or_args)
2016-05-22 05:20:29 +00:00
print('--- Airports ---')
for airport in query.all():
print(airport.name)