Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
Cache and current time entry id locally after starting to record
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Sassnowski committed May 18, 2018
1 parent 1e623b4 commit 85f3b18
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions kimai.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,36 @@ def start_recording(task_id, project_id):
project_id,
task_id
)
return KimaiResponse(_do_request(payload))

response = KimaiResponse(_do_request(payload))

if response.successful:
current = get_current()
config.set('CurrentEntry', current['timeEntryID'])

return response


def stop_recording():
"""Stops the running record if there is one."""
current_record = get_current()
time_entry_id = config.get('CurrentEntry')

if current_record is None:
return
if time_entry_id is None:
current_record = get_current()
time_entry_id = current_record['timeEntryID']

payload = _build_payload(
'stopRecord',
config.get('ApiKey'),
current_record['timeEntryID']
time_entry_id
)
return KimaiResponse(_do_request(payload))

response = KimaiResponse(_do_request(payload))

if response.successful:
config.delete('CurrentEntry')

return response


def get_current():
Expand Down

0 comments on commit 85f3b18

Please sign in to comment.