Skip to content

Instantly share code, notes, and snippets.

@Kutkovsky

Kutkovsky/togglproceed.py

Last active Oct 31, 2018
Embed
What would you like to do?
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