|
|
|
@ -15,13 +15,13 @@ logging.basicConfig(level=logging.INFO) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimeBot: |
|
|
|
|
def __init__(self, baseurl: str, user: str, password: str, employee_id: str): |
|
|
|
|
def __init__(self, baseurl: str, user: str, password: str): |
|
|
|
|
self.logger = logging.getLogger(self.__class__.__name__) |
|
|
|
|
self.baseurl = baseurl |
|
|
|
|
self.user = user |
|
|
|
|
self.password = password |
|
|
|
|
self.employee_id = employee_id |
|
|
|
|
self._session = None |
|
|
|
|
self._current_user = None |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def session(self): |
|
|
|
@ -68,7 +68,7 @@ class TimeBot: |
|
|
|
|
"periode0Time": punch_time, |
|
|
|
|
"selectedEntryCode": entry_code, |
|
|
|
|
"selectedPeriodType": 0, |
|
|
|
|
"employeeId": self.employee_id, |
|
|
|
|
"employeeId": self.get_current_user_id(), |
|
|
|
|
} |
|
|
|
|
if note: |
|
|
|
|
entry_data["note"] = note |
|
|
|
@ -76,10 +76,43 @@ class TimeBot: |
|
|
|
|
return request |
|
|
|
|
|
|
|
|
|
def list_employees(self): |
|
|
|
|
""" |
|
|
|
|
List all employees which are obviously in the same team as you. |
|
|
|
|
:return: list of employees |
|
|
|
|
""" |
|
|
|
|
request = self.session.get(self.baseurl + "Employee/GetEmployees") |
|
|
|
|
request.raise_for_status() |
|
|
|
|
return request.json() |
|
|
|
|
|
|
|
|
|
def _get_user_profile_for_current_user(self): |
|
|
|
|
""" |
|
|
|
|
Returns all user information for the current user. |
|
|
|
|
|
|
|
|
|
:return: all user information as dict |
|
|
|
|
""" |
|
|
|
|
request = self.session.get(self.baseurl + "Employee/GetUserProfileForCurrentUser") |
|
|
|
|
request.raise_for_status() |
|
|
|
|
return request.json() |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def current_user(self): |
|
|
|
|
""" |
|
|
|
|
Returns all user information for the current user. |
|
|
|
|
|
|
|
|
|
:return: all user information as dict |
|
|
|
|
""" |
|
|
|
|
if self._current_user is None: |
|
|
|
|
self._current_user = self._get_user_profile_for_current_user() |
|
|
|
|
return self._current_user |
|
|
|
|
|
|
|
|
|
def get_current_user_id(self): |
|
|
|
|
""" |
|
|
|
|
Get the current users id. |
|
|
|
|
|
|
|
|
|
:return: user id |
|
|
|
|
""" |
|
|
|
|
return self.current_user["employee"]["id"] |
|
|
|
|
|
|
|
|
|
def punch_in(self, punch_in_date: str, punch_in_time: str): |
|
|
|
|
""" |
|
|
|
|
:param str punch_in_date: date string in format: ``DD.MM.YYYY`` |
|
|
|
@ -117,7 +150,6 @@ if __name__ == '__main__': |
|
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
|
parser.add_argument("-v", help="enable debug logging", action="store_true") |
|
|
|
|
parser.add_argument("-u", help="mobatime login user", required=True) |
|
|
|
|
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') |
|
|
|
@ -142,7 +174,7 @@ if __name__ == '__main__': |
|
|
|
|
config = configparser.ConfigParser() |
|
|
|
|
config.read(args.c) |
|
|
|
|
|
|
|
|
|
tb = TimeBot(baseurl=config["general"]["baseurl"], user=args.u, password=password, employee_id=args.i) |
|
|
|
|
tb = TimeBot(baseurl=config["general"]["baseurl"], user=args.u, password=password) |
|
|
|
|
if args.subparser_name == "punch": |
|
|
|
|
if args.s == "now": |
|
|
|
|
now = datetime.now() |
|
|
|
|