add timestamp override for smart-punch command

master
Maximilian Zettler 4 years ago
parent aca809211a
commit 1630ca5a6c
  1. 18
      timebot.py

@ -301,8 +301,9 @@ if __name__ == '__main__':
help="use this command to auto punch in, punch out and create break " help="use this command to auto punch in, punch out and create break "
"entries; this command tries to detect your last action and will " "entries; this command tries to detect your last action and will "
"create entries in to following order: " "create entries in to following order: "
"punch_in(now) -> break_start(now) -> break_end(now) " "punch_in -> break_start -> break_end -> punch_out")
"-> punch_out(now)") parser_smart_punch.add_argument("-s", help=f"timestamp in format `{SIMPLE_DATETIME_FORMAT_HUMAN}` or `now`",
default="now")
args = parser.parse_args() args = parser.parse_args()
@ -326,8 +327,11 @@ if __name__ == '__main__':
)) ))
getattr(tb, args.t)(punch_datetime) getattr(tb, args.t)(punch_datetime)
elif args.subparser_name == "smart-punch": elif args.subparser_name == "smart-punch":
now = datetime.datetime.now() if args.s == "now":
last_punch = tb.get_entries(1, now.replace(hour=0, minute=0, second=0, microsecond=0)) punch_datetime = datetime.datetime.now()
else:
punch_datetime = datetime.datetime.strptime(args.s, SIMPLE_DATETIME_FORMAT)
last_punch = tb.get_entries(1, punch_datetime.replace(hour=0, minute=0, second=0, microsecond=0))
method = None method = None
if not last_punch: if not last_punch:
logger.debug("could not detect any time entry for today... punching in") logger.debug("could not detect any time entry for today... punching in")
@ -350,10 +354,10 @@ if __name__ == '__main__':
exit(1) exit(1)
logger.info("running `{}` with date `{}` and time `{}`".format( logger.info("running `{}` with date `{}` and time `{}`".format(
method, method,
now.strftime(SIMPLE_DATE_FORMAT), punch_datetime.strftime(SIMPLE_DATE_FORMAT),
now.strftime(SIMPLE_TIME_FORMAT), punch_datetime.strftime(SIMPLE_TIME_FORMAT),
)) ))
getattr(tb, method)(now) getattr(tb, method)(punch_datetime)
elif args.subparser_name == "list-entries": elif args.subparser_name == "list-entries":
end_date = None end_date = None
if args.end_date: if args.end_date:

Loading…
Cancel
Save