Skip to content

Instantly share code, notes, and snippets.

@nournia
Last active January 9, 2017 08:33
Show Gist options
  • Save nournia/4a8b6f9de31717d8f9697518ca9ab1c4 to your computer and use it in GitHub Desktop.
Save nournia/4a8b6f9de31717d8f9697518ca9ab1c4 to your computer and use it in GitHub Desktop.
# uses https://github.com/matthewdowney/TogglPy
from __future__ import print_function
import codecs
from TogglPy import Toggl
toggl = Toggl()
toggl.setAPIKey('<API_KEY>')
output = codecs.open('hours.csv', 'w', 'utf8')
YEARS = [2014, 2015, 2016, 2017]
workspaces = [item['id'] for item in toggl.request('https://www.toggl.com/api/v8/workspaces')]
for workspace in workspaces:
for year in YEARS:
for page in range(1, 20):
response = toggl.request('https://toggl.com/reports/api/v2/details?workspace_id={}&since={}-01-01&until={}-01-01&user_agent=api_test&page={}'.format(workspace, year, year+1, page))
if not response['data']:
break
for item in response['data']:
minutes, seconds = divmod(item['dur']/1000, 60)
hours, minutes = divmod(minutes, 60)
print(item['user'], item['start'][:10], '{}:{:0>2}:{:0>2}'.format(hours, minutes, seconds), item.get('project', ''), '"'+ item.get('description', '') +'"', sep=',', file=output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment