kopia lustrzana https://github.com/glidernet/ogn-python
Optional: filter airports by country
rodzic
a039ee3185
commit
943203804f
|
@ -2,14 +2,23 @@ from ogn.model import Airport
|
||||||
from ogn.commands.dbutils import session
|
from ogn.commands.dbutils import session
|
||||||
|
|
||||||
from manager import Manager
|
from manager import Manager
|
||||||
|
from sqlalchemy import and_, between
|
||||||
manager = Manager()
|
manager = Manager()
|
||||||
|
|
||||||
|
|
||||||
|
@manager.arg('country_code', help='filter by country code, eg. "de" for germany')
|
||||||
@manager.command
|
@manager.command
|
||||||
def list_all():
|
def list_all(country_code=None):
|
||||||
"""Show a list of all airports."""
|
"""Show a list of all airports."""
|
||||||
|
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)]
|
||||||
query = session.query(Airport) \
|
query = session.query(Airport) \
|
||||||
.order_by(Airport.name)
|
.order_by(Airport.name) \
|
||||||
|
.filter(*or_args)
|
||||||
|
|
||||||
print('--- Airports ---')
|
print('--- Airports ---')
|
||||||
for airport in query.all():
|
for airport in query.all():
|
||||||
|
|
Ładowanie…
Reference in New Issue