summaryrefslogtreecommitdiff
path: root/overlays
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2024-07-31 08:15:08 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2024-07-31 08:15:08 +0200
commit3c203b2eb88055d4e8a6cffecf257b9f1a2009d9 (patch)
treed32eff7b3371558667b376aed4ba86d4e8d02687 /overlays
parent122679ce1a17ebdf6eacbd12c0f50e140a295513 (diff)
downloadnixos-3c203b2eb88055d4e8a6cffecf257b9f1a2009d9.tar
nixos-3c203b2eb88055d4e8a6cffecf257b9f1a2009d9.tar.gz
nixos-3c203b2eb88055d4e8a6cffecf257b9f1a2009d9.tar.bz2
nixos-3c203b2eb88055d4e8a6cffecf257b9f1a2009d9.tar.xz
nixos-3c203b2eb88055d4e8a6cffecf257b9f1a2009d9.zip
...
Diffstat (limited to 'overlays')
-rwxr-xr-xoverlays/worktime/worktime/__main__.py20
1 files changed, 10 insertions, 10 deletions
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
38from hashlib import blake2s 38from hashlib import blake2s
39 39
40class TogglAPISection(Enum): 40class TogglAPISection(Enum):
41 TOGGL = '/api/v8' 41 TOGGL = '/api/v9'
42 REPORTS = '/reports/api/v2' 42 REPORTS = '/reports/api/v2'
43 43
44class TogglAPIError(Exception): 44class TogglAPIError(Exception):
@@ -58,7 +58,7 @@ class TogglAPI(object):
58 self._workspace_id = workspace_id 58 self._workspace_id = workspace_id
59 self._client_ids = set(map(int, client_ids.split(','))) if client_ids else None 59 self._client_ids = set(map(int, client_ids.split(','))) if client_ids else None
60 60
61 def _make_url(self, api=TogglAPISection.TOGGL, section=['time_entries', 'current'], params={}): 61 def _make_url(self, api=TogglAPISection.TOGGL, section=['me', 'time_entries', 'current'], params={}):
62 if api is TogglAPISection.REPORTS: 62 if api is TogglAPISection.REPORTS:
63 params.update({'user_agent': 'worktime', 'workspace_id': self._workspace_id}) 63 params.update({'user_agent': 'worktime', 'workspace_id': self._workspace_id})
64 64
@@ -176,34 +176,34 @@ class TogglAPI(object):
176 return billable_acc 176 return billable_acc
177 177
178 def get_running_clock(self, now=datetime.now(timezone.utc)): 178 def get_running_clock(self, now=datetime.now(timezone.utc)):
179 url = self._make_url(api = TogglAPISection.TOGGL, section = ['time_entries', 'current']) 179 url = self._make_url(api = TogglAPISection.TOGGL, section = ['me', 'time_entries', 'current'])
180 r = self._query(url = url, method='GET') 180 r = self._query(url = url, method='GET')
181 181
182 if not r or not r.json(): 182 if not r or not r.json():
183 raise TogglAPIError(r) 183 raise TogglAPIError(r)
184 184
185 if not r.json()['data'] or not r.json()['data']['billable']: 185 if not r.json() or not r.json()['billable']:
186 return None 186 return None
187 187
188 if self._client_ids is not None: 188 if self._client_ids is not None:
189 if 'pid' in r.json()['data'] and r.json()['data']['pid']: 189 if 'pid' in r.json() and r.json()['pid']:
190 url = self._make_url(api = TogglAPISection.TOGGL, section = ['projects', str(r.json()['data']['pid'])]) 190 url = self._make_url(api = TogglAPISection.TOGGL, section = ['projects', str(r.json()['pid'])])
191 pr = self._query(url = url, method = 'GET') 191 pr = self._query(url = url, method = 'GET')
192 if not pr or not pr.json(): 192 if not pr or not pr.json():
193 raise TogglAPIError(pr) 193 raise TogglAPIError(pr)
194 194
195 if not pr.json()['data']: 195 if not pr.json():
196 return None 196 return None
197 197
198 if 'cid' in pr.json()['data'] and pr.json()['data']['cid']: 198 if 'cid' in pr.json() and pr.json()['cid']:
199 if pr.json()['data']['cid'] not in self._client_ids: 199 if pr.json()['cid'] not in self._client_ids:
200 return None 200 return None
201 elif 0 not in self._client_ids: 201 elif 0 not in self._client_ids:
202 return None 202 return None
203 elif 0 not in self._client_ids: 203 elif 0 not in self._client_ids:
204 return None 204 return None
205 205
206 start = isoparse(r.json()['data']['start']) 206 start = isoparse(r.json()['start'])
207 207
208 return now - start if start <= now else None 208 return now - start if start <= now else None
209 209