def distanceBetween(system1, system2):
  try:
    coords1 = System(system1).coords
    coords2 = System(system2).coords
  except ServerError as e:
    print(e)
    sys.exit(1)
  except NotFoundError as e:
    print(e)
    syst.exit(2)
  else:
    print(int(round(math.sqrt( (coords1['x']-coords2['x'])**2
        + (coords1['y']-coords2['y'])**2
        + (coords1['z']-coords2['z'])**2 ),0)))
    sys.exit(0)
 def runsearch(event=None):
     for child in frame.winfo_children():
         child.grid_remove()
         child.destroy()
     try:
         system = System(systemField.get())
         distances = getDistances(system, cmdrs)
         nearestCmdr = min(distances, key=distances.get)
         lbl = tk.Label(frame,
                        text='nearest CMDR: {} ({} ly from {})'.format(
                            nearestCmdr.name, distances[nearestCmdr],
                            system.name))
         lbl.grid(row=0, columnspan=2)
         row = 1
         for cmdr in distances:
             row += 1
             lbl = tk.Label(frame, text='{}:'.format(cmdr.name))
             lbl.grid(row=row, column=0)
             lbl = tk.Label(frame, text='{} ly'.format(distances[cmdr]))
             lbl.grid(row=row, column=1)
     except (ServerError, SystemNotFoundError) as e:
         lbl = tk.Label(frame, text=e)
         lbl.grid(row=0, columnspan=2)
     except EdsmApiException as e:
         lbl = tk.Label(frame, text=e)
         lbl.grid(row=0, columnspan=2)
def getDistances (system, cmdrs):
  systemcoords = System(system).coords
  distances = {}
  for cmdr in cmdrs:
    cmdrcoords = getCmdrCoords(cmdr)
    distances[cmdr] = round(distance(cmdrcoords, systemcoords))
  return distances
def getBodyCount(system):
  try:
    bodyCount = System(system).bodyCount
  except ServerError as e:
    print(e)
    sys.exit(1)
  except NotFoundError as e:
    print(e)
    sys.exit(2)
  else:
    print(bodyCount)
    sys.exit(0)
def getBodyCount(system):
    return System(system).bodyCount
parser.add_argument('--system',
                    nargs=1,
                    help='the target system (must be in ' + 'EDDN!)',
                    required=True)
parser.add_argument('--short',
                    action='store_true',
                    help='short output (only ' + 'makes sense with `--text`)')
group = parser.add_mutually_exclusive_group()
group.add_argument('--gui', action='store_true', help='explicitly run the GUI')
group.add_argument('--text',
                   action='store_true',
                   help='explicitly give text output')

args = parser.parse_args()

system = System(args.system[0].strip().replace(' ', '').replace('', ''))
cmdrs = []
for name in args.cmdrs:
    cmdrs += [Commander(name)]
shortOutput = args.short

# =================================================================================

if args.text:
    outputText()
elif args.gui:
    outputGui()
else:
    try:
        outputGui()
    except tk.TclError: