2021-10-10 10:32:28 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import asyncio
|
2021-11-04 17:13:24 +00:00
|
|
|
|
2021-10-29 09:26:39 +00:00
|
|
|
from obs.face.osm import DataSource, DatabaseTileSource, OverpassTileSource
|
2021-10-10 10:32:28 +00:00
|
|
|
|
2021-11-14 22:42:02 +00:00
|
|
|
from obs.api.db import make_session, connect_db, make_session
|
2021-11-04 17:13:24 +00:00
|
|
|
from obs.api.app import app
|
2021-11-14 22:42:02 +00:00
|
|
|
from obs.api.process import process_tracks, process_tracks_loop
|
2021-10-10 10:32:28 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s")
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="processes a single track for use in the portal, "
|
|
|
|
"using the obs.face algorithms"
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
2021-11-04 17:13:24 +00:00
|
|
|
"--loop-delay",
|
2021-10-10 10:32:28 +00:00
|
|
|
action="store",
|
2021-11-04 17:13:24 +00:00
|
|
|
type=int,
|
|
|
|
default=10,
|
|
|
|
help="delay between loops, if no track was found in the queue (polling)",
|
2021-10-10 10:32:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
2021-11-04 17:13:24 +00:00
|
|
|
"tracks",
|
|
|
|
metavar="ID_OR_SLUG",
|
|
|
|
nargs="*",
|
|
|
|
help="ID or slug of tracks to process, if not passed, the queue is processed in a loop",
|
2021-10-10 10:32:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-11-04 17:13:24 +00:00
|
|
|
async with connect_db(app.config.POSTGRES_URL):
|
2021-11-14 22:42:02 +00:00
|
|
|
log.info("Loading OpenStreetMap data")
|
|
|
|
tile_source = DatabaseTileSource()
|
|
|
|
# tile_source = OverpassTileSource(app.config.OBS_FACE_CACHE_DIR)
|
|
|
|
data_source = DataSource(tile_source)
|
2021-11-04 17:13:24 +00:00
|
|
|
|
2021-11-14 22:42:02 +00:00
|
|
|
if args.tracks:
|
|
|
|
async with make_session() as session:
|
2021-11-04 17:13:24 +00:00
|
|
|
await process_tracks(session, data_source, args.tracks)
|
2021-10-29 09:26:39 +00:00
|
|
|
else:
|
2021-11-14 22:42:02 +00:00
|
|
|
await process_tracks_loop(data_source, args.loop_delay)
|
2021-10-10 10:32:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
asyncio.run(main())
|