-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloco.py
70 lines (56 loc) · 1.64 KB
/
loco.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import sys
import os
import click
from loguru import logger
# pylint: disable=no-name-in-module
from loco.loco_fastapi import service as httpsrv
import loco.controller as controller
@click.group()
@click.option("--google_api_key")
@click.option("--here_app_id")
@click.option("--here_app_code")
def cli(google_api_key, here_app_id, here_app_code):
"""
This applciation will return the lat/lon from any one of several
web services.
"""
if google_api_key:
os.environ["GOOGLE_API_KEY"] = google_api_key
if here_app_id:
os.environ["HERE_APP_ID"] = here_app_id
if here_app_code:
os.environ["HERE_APP_CODE"] = here_app_code
@click.command(help="Start the API server")
@click.option("--service_port")
def proxy(service_port):
if service_port:
os.environ["SERVICE_PORT"] = service_port
httpsrv.start()
return True
@click.command(help="Search for the given address")
@click.argument("address")
def query(address):
try:
locations = controller.search(address)
except controller.NoGeoCodeServicesAvailable:
print("No proxied services are available at this moment")
return False
for loc in locations:
print(
"{provider}: lat: {lat}, lon: {lon} Address: {addr}".format(
lat=loc["lat"],
lon=loc["lon"],
provider=loc["provider"],
addr=loc["address"],
)
)
return True
def main():
# pylint: disable=no-value-for-parameter
cli()
return True
cli.add_command(query)
cli.add_command(proxy)
if __name__ == "__main__":
sys.exit(main())