|
|
|
@ -212,6 +212,14 @@ if __name__ == '__main__': |
|
|
|
|
f"(default: now; unset for default)") |
|
|
|
|
parser_list_entries.add_argument("--items", help="max items to request per page", default=20, type=int) |
|
|
|
|
|
|
|
|
|
# subparser command: `smart-punch` |
|
|
|
|
parser_smart_punch = subparsers.add_parser("smart-punch", |
|
|
|
|
help="use this command to auto punch in, punch out and create break " |
|
|
|
|
"entries; this command tries to detect your last action and will " |
|
|
|
|
"create entries in to following order: " |
|
|
|
|
"punch_in(now) -> break_start(now) -> break_end(now) " |
|
|
|
|
"-> punch_out(now)") |
|
|
|
|
|
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
if args.v: |
|
|
|
@ -237,7 +245,29 @@ if __name__ == '__main__': |
|
|
|
|
)) |
|
|
|
|
getattr(tb, args.t)(punch_datetime) |
|
|
|
|
elif args.subparser_name == "smart-punch": |
|
|
|
|
pass |
|
|
|
|
now = datetime.datetime.now() |
|
|
|
|
last_punch = tb.get_entries(1, now.replace(hour=0, minute=0, second=0, microsecond=0)) |
|
|
|
|
method = None |
|
|
|
|
if not last_punch: |
|
|
|
|
logger.info("could not detect any time entry for today... punching in") |
|
|
|
|
method = "punch_in" |
|
|
|
|
elif last_punch[0]["entryNumber"] == COMING_ENTRY_CODE_ID: |
|
|
|
|
logger.info("your last entry was `punch_in`... starting break") |
|
|
|
|
method = "break_start" |
|
|
|
|
elif last_punch[0]["entryNumber"] == BREAK_START_ENTRY_CODE_ID: |
|
|
|
|
logger.info("your last entry was `break_start`... ending break") |
|
|
|
|
method = "break_end" |
|
|
|
|
elif last_punch[0]["entryNumber"] == BREAK_END_ENTRY_CODE_ID: |
|
|
|
|
logger.info("your last entry was `break_end`... punching out") |
|
|
|
|
method = "punch_out" |
|
|
|
|
elif last_punch[0]["entryNumber"] == LEAVING_ENTRY_CODE_ID: |
|
|
|
|
logger.error("your last entry was `punch_out`... punching in again with this command is not supported") |
|
|
|
|
sys.exit(1) |
|
|
|
|
if method is None: |
|
|
|
|
logger.error("hit an unknown situation... detection failed; run with `-v` for more info") |
|
|
|
|
logger.debug(f"last entry was: {last_punch}") |
|
|
|
|
exit(1) |
|
|
|
|
getattr(tb, method)(now) |
|
|
|
|
elif args.subparser_name == "list-entries": |
|
|
|
|
end_date = None |
|
|
|
|
if args.end_date: |
|
|
|
|