|
|
|
@ -2,10 +2,13 @@ import argparse |
|
|
|
|
import configparser |
|
|
|
|
import getpass |
|
|
|
|
import logging |
|
|
|
|
import sys |
|
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
import requests as requests |
|
|
|
|
|
|
|
|
|
from constants import COMING_ENTRY_CODE_ID, LEAVING_ENTRY_CODE_ID |
|
|
|
|
from constants import COMING_ENTRY_CODE_ID, LEAVING_ENTRY_CODE_ID, PUNCH_COMMANDS, BREAK_START_ENTRY_CODE_ID, \ |
|
|
|
|
BREAK_END_ENTRY_CODE_ID |
|
|
|
|
|
|
|
|
|
logger = logging.getLogger() |
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
@ -93,6 +96,22 @@ class TimeBot: |
|
|
|
|
""" |
|
|
|
|
self.add_entry(punch_out_date, punch_out_time, LEAVING_ENTRY_CODE_ID, note="weg").raise_for_status() |
|
|
|
|
|
|
|
|
|
def break_start(self, punch_date: str, punch_time: str): |
|
|
|
|
""" |
|
|
|
|
:param str punch_date: date string in format: ``DD.MM.YYYY`` |
|
|
|
|
:param str punch_time: time string in format: ``hh:mm`` |
|
|
|
|
:raises: on status code != 2xx |
|
|
|
|
""" |
|
|
|
|
self.add_entry(punch_date, punch_time, BREAK_START_ENTRY_CODE_ID, note="pause").raise_for_status() |
|
|
|
|
|
|
|
|
|
def break_end(self, punch_date: str, punch_time: str): |
|
|
|
|
""" |
|
|
|
|
:param str punch_date: date string in format: ``DD.MM.YYYY`` |
|
|
|
|
:param str punch_time: time string in format: ``hh:mm`` |
|
|
|
|
:raises: on status code != 2xx |
|
|
|
|
""" |
|
|
|
|
self.add_entry(punch_date, punch_time, BREAK_END_ENTRY_CODE_ID, note="pause ende").raise_for_status() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
@ -101,6 +120,16 @@ if __name__ == '__main__': |
|
|
|
|
parser.add_argument("-i", help="mobatime employee id", required=True) |
|
|
|
|
parser.add_argument("-p", help="mobatime login user password", default=None) |
|
|
|
|
parser.add_argument("-c", help="config file", default="timebot.ini") |
|
|
|
|
subparsers = parser.add_subparsers(help='sub-command help', dest='subparser_name') |
|
|
|
|
|
|
|
|
|
parser_punch = subparsers.add_parser("punch", |
|
|
|
|
help="use this command to punch in, punch out, or create break entries") |
|
|
|
|
parser_punch.add_argument("-t", |
|
|
|
|
help="type of time entry; this can be `punch_in`, `punch_out`, `break_start`, `break_end`", |
|
|
|
|
default="punch_in", |
|
|
|
|
choices=PUNCH_COMMANDS) |
|
|
|
|
parser_punch.add_argument("-s", help="timestamp in format `DD.MM.YYYY_hh:mm` or `now`", default="now") |
|
|
|
|
|
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
if args.v: |
|
|
|
@ -114,5 +143,18 @@ if __name__ == '__main__': |
|
|
|
|
config.read(args.c) |
|
|
|
|
|
|
|
|
|
tb = TimeBot(baseurl=config["general"]["baseurl"], user=args.u, password=password, employee_id=args.i) |
|
|
|
|
tb.punch_in("23.11.2021", "09:00") |
|
|
|
|
tb.punch_out("23.11.2021", "18:00") |
|
|
|
|
if args.subparser_name == "punch": |
|
|
|
|
if args.s == "now": |
|
|
|
|
now = datetime.now() |
|
|
|
|
punch_date = now.strftime("%d.%m.%Y") |
|
|
|
|
punch_time = now.strftime("%H:%M") |
|
|
|
|
else: |
|
|
|
|
punch_date = args.s.split("_")[0] |
|
|
|
|
punch_time = args.s.split("_")[1] |
|
|
|
|
logger.info("running `{}` with date `{}` and time `{}`".format(args.t, punch_date, punch_time)) |
|
|
|
|
getattr(tb, args.t)(punch_date, punch_time) |
|
|
|
|
else: |
|
|
|
|
logger.error("Noting done... dunno what you want!") |
|
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
|
sys.exit(0) |
|
|
|
|