From e54079e281bf88e6a06e4d15d6cbfff003ceef43 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 29 May 2024 12:10:24 +0200 Subject: ... --- accounts/gkleen@sif/default.nix | 2 +- accounts/gkleen@sif/ssh-hosts.nix | 5 +++++ overlays/worktime/worktime/__main__.py | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/accounts/gkleen@sif/default.nix b/accounts/gkleen@sif/default.nix index 05cfc2c8..86a15c44 100644 --- a/accounts/gkleen@sif/default.nix +++ b/accounts/gkleen@sif/default.nix @@ -143,7 +143,7 @@ in { # ProxyCommand ${pkgs.socat}/bin/socat - SOCKS4A:127.0.0.1:%h:%p,socksport=8118 ProxyJump ssh.math.lmu.de - Match host *.cipmath.loc !host cip04.cipmath.loc !exec "nc -z -w 1 %h %p &>/dev/null" + Match host *.cipmath.loc !host cip04.cipmath.loc,mgmt-cls01.cipmath.loc !exec "nc -z -w 1 %h %p &>/dev/null" ProxyJump cip04 Match host *.ifi.lmu.de,*.math.lmu.de diff --git a/accounts/gkleen@sif/ssh-hosts.nix b/accounts/gkleen@sif/ssh-hosts.nix index f141ca8e..ea714910 100644 --- a/accounts/gkleen@sif/ssh-hosts.nix +++ b/accounts/gkleen@sif/ssh-hosts.nix @@ -445,6 +445,11 @@ { hostname = "cip04.cipmath.loc"; proxyJump = "mathw0h"; }; + "mgmt-cls01" = + { user = "root"; + hostname = "mgmt-cls01.cipmath.loc"; + proxyJump = "ssh.math.lmu.de"; + }; "mgmt01" = { hostname = "mgmt01.mathinst.loc"; proxyJump = "mathw0h"; diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 154c1966..dddbb250 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -38,7 +38,7 @@ import jsonpickle from hashlib import blake2s class TogglAPISection(Enum): - TOGGL = '/api/v8' + TOGGL = '/api/v9' REPORTS = '/reports/api/v2' class TogglAPIError(Exception): @@ -58,7 +58,7 @@ class TogglAPI(object): self._workspace_id = workspace_id self._client_ids = set(map(int, client_ids.split(','))) if client_ids else None - def _make_url(self, api=TogglAPISection.TOGGL, section=['time_entries', 'current'], params={}): + def _make_url(self, api=TogglAPISection.TOGGL, section=['me', 'time_entries', 'current'], params={}): if api is TogglAPISection.REPORTS: params.update({'user_agent': 'worktime', 'workspace_id': self._workspace_id}) @@ -80,7 +80,7 @@ class TogglAPI(object): max_time=10, ) def _raw_query(self, url, method): - headers = {'content-type': 'application/json'} + headers = {'content-type': 'application/json', 'accept': 'application/json'} response = None if method == 'GET': @@ -176,34 +176,34 @@ class TogglAPI(object): return billable_acc def get_running_clock(self, now=datetime.now(timezone.utc)): - url = self._make_url(api = TogglAPISection.TOGGL, section = ['time_entries', 'current']) + url = self._make_url(api = TogglAPISection.TOGGL, section = ['me', 'time_entries', 'current']) r = self._query(url = url, method='GET') - if not r or not r.json(): - raise TogglAPIError(r) + if not r: + raise TogglAPIError(None, r) - if not r.json()['data'] or not r.json()['data']['billable']: + if not r.json() or not r.json()['billable']: return None if self._client_ids is not None: - if 'pid' in r.json()['data'] and r.json()['data']['pid']: - url = self._make_url(api = TogglAPISection.TOGGL, section = ['projects', str(r.json()['data']['pid'])]) + if 'pid' in r.json() and r.json()['pid']: + url = self._make_url(api = TogglAPISection.TOGGL, section = ['workspaces', self._workspace_id, 'projects', str(r.json()['pid'])]) pr = self._query(url = url, method = 'GET') if not pr or not pr.json(): raise TogglAPIError(pr) - if not pr.json()['data']: + if not pr.json(): return None - if 'cid' in pr.json()['data'] and pr.json()['data']['cid']: - if pr.json()['data']['cid'] not in self._client_ids: + if 'cid' in pr.json() and pr.json()['cid']: + if pr.json()['cid'] not in self._client_ids: return None elif 0 not in self._client_ids: return None elif 0 not in self._client_ids: return None - start = isoparse(r.json()['data']['start']) + start = isoparse(r.json()['start']) return now - start if start <= now else None -- cgit v1.2.3