From 3c203b2eb88055d4e8a6cffecf257b9f1a2009d9 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 31 Jul 2024 08:15:08 +0200 Subject: ... --- overlays/worktime/worktime/__main__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'overlays') diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 154c1966..5630837b 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}) @@ -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.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 = ['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