#!/usr/bin/env python
#
# LaunchBar Action Script
#
from toggl.TogglPy import Toggl
from requests import HTTPError
import datetime

# %%
toggl = Toggl()
# fill your own E-Mail and Password.
toggl.setAuthCredentials('<EMAIL>', '<PASSWORD>')

# %%
try:
    currentTimer = toggl.currentRunningTimeEntry()
    if currentTimer['data'] is None:
        print('No Time Entry Runnig Now.')
    else:
        stoppedEntry = toggl.stopTimeEntry(currentTimer['data']['id'])['data']
        duration_str = str(datetime.timedelta(0, stoppedEntry['duration']))
        print('Stopped: {}, Have Run {}.'.format(stoppedEntry['description'],
                                                 duration_str))
except HTTPError as e:
    print(e)
Beispiel #2
0
config = configparser.ConfigParser()
config.sections()
config.read('config.ini')

# Get Toggl config
toggl = Toggl()

TogglConfig = config['Toggl']
SettingsConfig = config['Settings']

if TogglConfig['auth_token']:
    print('Using Toggl token for authentication')
    toggl.setAPIKey(TogglConfig['user_token'])
elif TogglConfig['auth_email']:
    print('Using Toggl email and password for authentication')
    toggl.setAuthCredentials(TogglConfig['user_email'],
                             TogglConfig['user_password'])
else:
    raise Exception('Please configure your Toggl authentication.')

# Timer
working = False

while True:

    currentEntry = toggl.request(
        'https://www.toggl.com/api/v8/time_entries/current')

    if currentEntry["data"] == None and working == True:
        working = False
        print("Not Working")
    elif currentEntry["data"] != None and working == False: