-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (30 loc) · 1.01 KB
/
main.py
File metadata and controls
40 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from toggl.TogglPy import Toggl
import configparser
import time
# Get config
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:
working = True
print("Working")
time.sleep(int(SettingsConfig['interval']))