Skip to content

Instantly share code, notes, and snippets.

@Kutkovsky
Last active October 31, 2018 15:06
Show Gist options
  • Save Kutkovsky/98b3ea748b4477c2b254bb8d9c097a6b to your computer and use it in GitHub Desktop.
Save Kutkovsky/98b3ea748b4477c2b254bb8d9c097a6b to your computer and use it in GitHub Desktop.
Togglproceed.py
#!/usr/local/bin/python3
import csv
import xlwt
'''
TODO: import report automatically from toggl.com (token: '<your token here>')
curl -v -u <your token here>:api_token -X GET "https://toggl.com/api/v8/workspaces"
curl -v -u <your token here>:api_token -X GET "https://toggl.com/reports/api/v2/details?page=<report_page_since_its_paginated>&workspace_id=<ourworkspacenumber>&since=2018-10-01&until=2018-10-31&user_agent=api_test"
'''
TOGGLE_CSV = 'Toggl_time_entries_2018-10-01_to_2018-10-31.csv'
ETS_XLS = 'ets.xls'
wb = open(TOGGLE_CSV)
reader = csv.reader(wb)
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Sheet 1")
# We need Cols: 3, empty, 5, 7, 9 for `Project`, `Effort`, `Task
# description`, `Start date`, `End date`
i = -1
for row in reader:
i += 1
if i == 0: # skip first row
continue
time = row[11] # We using `Duration` value for the effort calculation
effort = int(time[0:2]) + int(int(time[3:5])) / 60 + \
int(int(time[6:7])) / 3600 # Hourly effort formulae
sheet1.write(i-1, 0, str(row[3]))
sheet1.write(i-1, 1, str(f'{effort:.2f}'))
sheet1.write(i-1, 2, str(row[5]))
sheet1.write(i-1, 3, str(row[7]))
sheet1.write(i-1, 4, str(row[9]))
book.save(ETS_XLS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment