spansh.py: added --parsable
format to nearestsystem
This commit is contained in:
parent
07ca9ec406
commit
15a8deca65
2 changed files with 13 additions and 4 deletions
|
@ -155,7 +155,8 @@ subcommands:
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: spansh.py nearestsystem [-h] [--short] coordinate coordinate coordinate
|
usage: spansh.py nearestsystem [-h] [--short | --parsable]
|
||||||
|
coordinate coordinate coordinate
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
coordinate the coordinates to search for (order: x, y, z)
|
coordinate the coordinates to search for (order: x, y, z)
|
||||||
|
@ -163,6 +164,7 @@ positional arguments:
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
--short short output format (system name only)
|
--short short output format (system name only)
|
||||||
|
--parsable parsable output format (<name>|<x>,<y>,<z>|<distance>)
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
13
spansh.py
13
spansh.py
|
@ -17,9 +17,13 @@ def getNearestSystem(coords):
|
||||||
}
|
}
|
||||||
json = requests.post(APIURLS["nearest"], params).json()
|
json = requests.post(APIURLS["nearest"], params).json()
|
||||||
|
|
||||||
ret = ""
|
ret = None
|
||||||
|
system = json["system"]
|
||||||
if args.short:
|
if args.short:
|
||||||
ret = json["system"]["name"]
|
ret = system["name"]
|
||||||
|
elif args.parsable:
|
||||||
|
ret = "{}|{},{},{}|{}".format(system["name"], system["x"],
|
||||||
|
system["y"], system["z"], round(system["distance"], 2))
|
||||||
else:
|
else:
|
||||||
system = json["system"]
|
system = json["system"]
|
||||||
ret = "{} ({}, {}, {}), {} ly".format(system["name"], system["x"],
|
ret = "{} ({}, {}, {}), {} ly".format(system["name"], system["x"],
|
||||||
|
@ -77,8 +81,11 @@ parser_nearestsystem = subparsers.add_parser("nearestsystem",
|
||||||
help="Searches for the nearest system in the database to given coordinates.")
|
help="Searches for the nearest system in the database to given coordinates.")
|
||||||
parser_nearestsystem.add_argument("coordinate", nargs=3, type=int,
|
parser_nearestsystem.add_argument("coordinate", nargs=3, type=int,
|
||||||
help="the coordinates to search for (order: x, y, z)")
|
help="the coordinates to search for (order: x, y, z)")
|
||||||
parser_nearestsystem.add_argument("--short", action='store_true',
|
group = parser_nearestsystem.add_mutually_exclusive_group(required=False)
|
||||||
|
group.add_argument("--short", action='store_true',
|
||||||
help="short output format (system name only)")
|
help="short output format (system name only)")
|
||||||
|
group.add_argument("--parsable", action='store_true',
|
||||||
|
help="parsable output format (<name>|<x>,<y>,<z>|<distance>)")
|
||||||
|
|
||||||
parser_oldstations = subparsers.add_parser("oldstations",
|
parser_oldstations = subparsers.add_parser("oldstations",
|
||||||
help="Searches for stations with old data (>1 year without an update.")
|
help="Searches for stations with old data (>1 year without an update.")
|
||||||
|
|
Loading…
Reference in a new issue