2021-05-02 22:27:51 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import configparser
|
2021-06-02 16:13:31 +00:00
|
|
|
import json
|
2021-05-02 22:27:51 +00:00
|
|
|
import os
|
2024-11-24 17:07:00 +00:00
|
|
|
import sys
|
2021-05-02 22:27:51 +00:00
|
|
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config['pomodoro'] = {}
|
|
|
|
pomodoro = config['pomodoro']
|
2021-06-02 16:13:31 +00:00
|
|
|
config['harvest'] = {}
|
|
|
|
harvest = config['harvest']
|
2021-05-02 22:27:51 +00:00
|
|
|
|
2021-05-25 20:00:09 +00:00
|
|
|
def write():
|
|
|
|
with open('settings.ini', 'w') as configfile:
|
|
|
|
config.write(configfile)
|
|
|
|
|
|
|
|
|
2021-05-02 22:27:51 +00:00
|
|
|
if not os.path.isfile('settings.ini'):
|
|
|
|
# Set some essential initial values.
|
2021-05-28 18:24:07 +00:00
|
|
|
|
|
|
|
# pomodoro['logfile'] = '~/Projects/agaric/python/pomodoroprompt/log/timelog.csv'
|
|
|
|
pomodoro['logfile'] = ''
|
|
|
|
|
|
|
|
# This path must be absolute, for some reason using ~ for home isn't working:
|
2024-11-26 03:56:38 +00:00
|
|
|
pomodoro['logpath'] = '~/Projects/python/pomodoroprompt/log/'
|
2021-05-03 00:30:14 +00:00
|
|
|
write()
|
2021-05-02 22:27:51 +00:00
|
|
|
|
|
|
|
config.read('settings.ini')
|
|
|
|
|
2021-05-03 00:30:14 +00:00
|
|
|
|
2021-05-02 22:27:51 +00:00
|
|
|
def pomodoro_logfile():
|
|
|
|
return config['pomodoro']['logfile']
|
|
|
|
|
2021-05-25 19:58:28 +00:00
|
|
|
def pomodoro_logpath():
|
|
|
|
return config['pomodoro']['logpath']
|
|
|
|
|
2021-05-03 03:19:40 +00:00
|
|
|
def pomodoro_latest_recorded(timestamp = None):
|
|
|
|
if timestamp:
|
2021-08-17 19:15:17 +00:00
|
|
|
config.set('pomodoro', 'second_latest_recorded', pomodoro.get('latest_recorded', None))
|
2021-05-03 03:19:40 +00:00
|
|
|
config.set('pomodoro', 'latest_recorded', str(timestamp))
|
2021-05-03 00:30:14 +00:00
|
|
|
write()
|
2021-05-02 22:27:51 +00:00
|
|
|
else:
|
2021-05-03 00:30:14 +00:00
|
|
|
return pomodoro.get('latest_recorded', None)
|
2021-06-02 16:13:31 +00:00
|
|
|
|
|
|
|
def harvest_set_projects_clients_map(projects_clients_map = {}):
|
|
|
|
config.set('harvest', 'projects_clients', json.dumps(projects_clients_map))
|
|
|
|
write()
|
|
|
|
|
|
|
|
def harvest_get_projects_clients_map():
|
2024-11-24 17:07:00 +00:00
|
|
|
if 'projects_clients' in harvest:
|
|
|
|
return json.loads(harvest['projects_clients'])
|
|
|
|
else:
|
|
|
|
sys.exit("No project clients available; run fetch_clients_projects.py")
|