From 13510f982496154201b64ebe5f2959edd2571898 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Thu, 16 Jan 2020 18:50:23 +0100 Subject: [PATCH] findcommander now gives a date for the known position --- README.md | 4 +++- explorationtools.py | 25 +++++++++++++++++++++++-- pyEDSM | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 326f0be..0c7d767 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,9 @@ subcommands: systems could not be found on EDSM. findcommander Attempts to find a CMDR’s last known position. Will exit with code 1 on server error and code 2 if the - CMDR could not be found on EDSM. + CMDR could not be found on EDSM. Will also give you + the time of last activity if you search for their + system. findsystem Attempts to find a partially matching system that should then hopefully be in the vicinity of the given system diff --git a/explorationtools.py b/explorationtools.py index 414394c..8194297 100755 --- a/explorationtools.py +++ b/explorationtools.py @@ -3,6 +3,7 @@ import argcomplete, argparse import math import sys +from datetime import datetime from pyEDSM.edsm.exception import ServerError, NotFoundError from pyEDSM.edsm.models import System, Commander @@ -30,7 +31,26 @@ def getCommanderProfileUrl(name, apikey): return Commander(name, apikey).profileUrl def getCommanderSystem(name, apikey): - return Commander(name, apikey).currentSystem + cmdr = Commander(name, apikey) + return "{} (last seen {})".format(cmdr.currentSystem, + when(cmdr.lastActivity)) +def when(date): + diff = datetime.now() - date + ret = "" + if diff.days > 0: + ret += "{} days ".format(diff.days) + if diff.seconds > 0: + hours = int(diff.seconds / 3600) + if hours > 0: + ret += "{} hours ".format(hours) + minutes = int(diff.seconds % 3600 / 60) + if minutes > 0: + ret += "{} minutes ".format(minutes) + if diff.days == 0 and hours == 0 and minutes == 0: + # ONLY seconds! + ret = "{} seconds ".format(diff.seconds) + ret += "ago" + return ret def getSystemList(name): systems = System.getSystems(name) @@ -80,7 +100,8 @@ parser_distance.add_argument("system", nargs=2, help="the systems to measure") parser_findCmdr = subparsers.add_parser("findcommander", help="Attempts to find a CMDR’s last known position. Will exit with code 1 " - + "on server error and code 2 if the CMDR could not be found on EDSM.") + + "on server error and code 2 if the CMDR could not be found on EDSM. Will " + + "also give you the time of last activity if you search for their system.") group = parser_findCmdr.add_mutually_exclusive_group(required=False) group.add_argument('--system', action='store_true', help='output the commander’s last known system (default)') diff --git a/pyEDSM b/pyEDSM index 82519b9..dc18cbb 160000 --- a/pyEDSM +++ b/pyEDSM @@ -1 +1 @@ -Subproject commit 82519b9d668a2a3be2aea27126bc4cd44763132d +Subproject commit dc18cbb914dd5efeba14f4a2f0e2664219462c38