Set path for logfiles to be near home, not whereever run from

This commit is contained in:
benjamin melançon 2021-05-23 00:35:39 -04:00
parent 72b3baf57b
commit c04f849161

View file

@ -91,14 +91,16 @@ def countdown_to(until):
time.sleep(1)
def prepare_file(utc_start, ext='csv', daily=False):
# Save timelogs relative to script directory (NOT from where called)
logpath = os.path.dirname(os.path.realpath(__file__)) + '/log'
# Ensure log directory exists.
if not os.path.exists('log'):
os.makedirs('log')
if not os.path.exists(logpath):
os.makedirs(logpath)
# We consider 3am the switchover to a new day, so we skip extra math
# and use Pacific time to get three hours later than our Eastern time.
logpath_tz = timezone('US/Pacific')
logpath_date = utc_start.astimezone(logpath_tz)
timelog_path = 'log/' + str(logpath_date.year);
timelog_path = logpath + '/' + str(logpath_date.year);
if (daily):
timelog_path += '-' \
+ format(logpath_date.month, '02') + '-' \