Created
July 29, 2015 05:40
-
-
Save sesh/28224a31efc91f757160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
import arrow | |
import requests | |
# Grab your OAuth token from here: | |
# https://toggl.com/app/profile | |
TOGGL_API_TOKEN = '' | |
PROJECT_MAPPING = { | |
'sixty': '6291309', | |
'mentorloop': '2319897', | |
'lurpak': '9482176' | |
} | |
class Toggl(object): | |
def __init__(self, token): | |
self.token = token | |
def entry(self, start_time, end_time, project, description): | |
data = { | |
'time_entry': { | |
'description': description, | |
'pid': project, | |
'start': str(start_time), | |
'duration': (end_time - start_time).seconds, | |
'created_with': 't', | |
'billable': True, | |
} | |
} | |
response = requests.post('https://www.toggl.com/api/v8/time_entries', auth=(self.token, 'api_token'), json=data) | |
print response.status_code | |
def projects(self, workspace_id): | |
response = requests.get('https://www.toggl.com/api/v8/workspaces/{}/projects'.format(workspace_id), | |
auth=(self.token, 'api_token')) | |
return response.json() | |
def timiyay(filename): | |
t = Toggl(TOGGL_API_TOKEN) | |
# get projects for the Common Code workspace | |
# for t in t.projects('179261'): | |
# print p['id'], p['name'] | |
with open(filename) as f: | |
reader = csv.DictReader(f) | |
for row in reader: | |
start_time = arrow.get('{} {}'.format(row['Start date'], row['Start time'])).replace(tzinfo='Australia/Melbourne') | |
end_time = arrow.get('{} {}'.format(row['End date'], row['End time'])).replace(tzinfo='Australia/Melbourne') | |
t.entry(start_time, end_time, PROJECT_MAPPING[row['Project']], row['Description']) | |
sys.exit() | |
if __name__ == '__main__': | |
timiyay(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment