From e54079e281bf88e6a06e4d15d6cbfff003ceef43 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 29 May 2024 12:10:24 +0200 Subject: ... --- overlays/worktime/worktime/__main__.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'overlays') 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