Commit 7ac0ff3d authored by Brad Beyenhof's avatar Brad Beyenhof
Browse files

add python version: "streaks"

parent 93589e58
#!/usr/bin/env python3
import sys
import inspect
import os
from datetime import datetime
from dateutil import relativedelta
# Find config file, either next to the program or specified as an argument
try:
configfile = sys.argv[1]
except:
configfile = os.path.dirname(inspect.stack()[0][1]) + '/streaks.conf'
today = datetime.today()
print('STREAKS:')
with open(configfile) as fh:
for line in fh:
# Read config file and determine relative delta
*habit_name_list, habit_date_str = line.rstrip().split(' ')
habit_name = ' '.join(habit_name_list)
habit_date = datetime.strptime(habit_date_str, '%Y-%m-%d')
habit_diff = relativedelta.relativedelta(today, habit_date)
# Build relative delta string
habit_diff_str = ''
if habit_diff.years > 0:
habit_diff_str = habit_diff_str + str(habit_diff.years) + ' year'
if habit_diff.years != 1:
habit_diff_str = habit_diff_str + 's'
if not (habit_diff.months or habit_diff.days):
habit_diff_str = habit_diff_str + '!!'
else:
habit_diff_str = habit_diff_str + ', '
if habit_diff.months > 0:
habit_diff_str = habit_diff_str + str(habit_diff.months) + ' month'
if habit_diff.months != 1:
habit_diff_str = habit_diff_str + 's'
if not habit_diff.days:
habit_diff_str = habit_diff_str + '!'
else:
habit_diff_str = habit_diff_str + ', '
if habit_diff.days > 0:
habit_diff_str = habit_diff_str + str(habit_diff.days) + ' day'
if habit_diff.days != 1:
habit_diff_str = habit_diff_str + 's'
else:
if not (habit_diff.years or habit_diff.months):
habit_diff_str = 'No time yet!'
# Determine duration in days
if (habit_diff.years or habit_diff.months):
habit_diff_totaldays = " (" + str(today - habit_date).split(',')[0] + ")"
else:
habit_diff_totaldays = ""
# Display diffs
print('{habit}: {diff}'.format(habit=habit_name,diff=habit_diff_str))
print()
print()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment