summaryrefslogtreecommitdiff
path: root/overlays
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2024-05-29 12:10:24 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2024-05-29 12:10:24 +0200
commite54079e281bf88e6a06e4d15d6cbfff003ceef43 (patch)
treec22ba1100099f75ccf142f4b8b83ef270ac621c5 /overlays
parentde2521348c54e73c5260a15bd2d7eb214df24c60 (diff)
downloadnixos-e54079e281bf88e6a06e4d15d6cbfff003ceef43.tar
nixos-e54079e281bf88e6a06e4d15d6cbfff003ceef43.tar.gz
nixos-e54079e281bf88e6a06e4d15d6cbfff003ceef43.tar.bz2
nixos-e54079e281bf88e6a06e4d15d6cbfff003ceef43.tar.xz
nixos-e54079e281bf88e6a06e4d15d6cbfff003ceef43.zip
...
Diffstat (limited to 'overlays')
-rwxr-xr-xoverlays/worktime/worktime/__main__.py26
1 files changed, 13 insertions, 13 deletions
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
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
@@ -80,7 +80,7 @@ class TogglAPI(object):
80 max_time=10, 80 max_time=10,
81 ) 81 )
82 def _raw_query(self, url, method): 82 def _raw_query(self, url, method):
83 headers = {'content-type': 'application/json'} 83 headers = {'content-type': 'application/json', 'accept': 'application/json'}
84 response = None 84 response = None
85 85
86 if method == 'GET': 86 if method == 'GET':
@@ -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:
183 raise TogglAPIError(r) 183 raise TogglAPIError(None, 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 = ['workspaces', self._workspace_id, '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