Gettin’ it Together…Again

So, I don’t have a job anymore. I will spare you the details but I left and wont be going back. Some people really suck. Its been 2 days since.

Now that I have the entirety of my time back to myself at least for a little while while I look for another job, I am going to use this time to get myself back to a good routine like I had before I started that humanity eroding job.

The current plan is to exercise more, work on increasing my typing speed (because why not), write in my journal and meditate. I made a little piece to run at the start of every terminal I start to help remind me throughout the day of the things I have to do. Writing this I can think of a few more to add to it.

Anyway, here is the code and a screenshot of the output:

import blessed
import random
import datetime
import argparse

tasks = {
1:'Work Out',
2:'30 MIN Typing Practice',
3:'Write in Journal',
4:'Meditate'}

# checks for file
def file_check(file, term):
    try:
        with open(file, 'r', errors='ignore'):
            pass
    except FileNotFoundError:
        opt = input('Task file not found. Create file now? (y/n): ')
        if opt.lower() == 'y':
            with open(file, 'w') as f:
                pass
            print(f'{file} created.')
            try:
                with open(file, 'w', encoding='utf-8') as f:
                    today = datetime.date.today().strftime('%Y-%m-%d')
                    for task in tasks.values():
                        content = f"{today}:{task}:False\n"
                        f.write(content)
            except:
                print(f'Error')
        elif opt.lower() == 'n':
            print('Exiting.')
        else:
            print('Invalid option.')
   
    except Exception as e:
        print(f'Error: {e}')

# Entry example: date:task:True/False
def check_complete(file, term):
    tasks = []
    today = datetime.date.today().strftime('%Y-%m-%d')

    with open(file, 'r') as f:
        lines = f.readlines()

        for line in lines:
            line = line.strip().split(':')
            if line[0] == today:
                tasks.append(line)
    return tasks

def to_do_list(file, term):
    tasks = check_complete(file, term)
    today = datetime.date.today().strftime('%Y-%m-%d')
    print(f'{term.orange}Daily Tasks for {term.yellow}{today}')

    for task in tasks:
        if task[2] == 'True':
            print(f'{term.green}[*]{term.white}: {task[1]}')
        elif task[2] == 'False':
            print(f'{term.red}[ ]{term.white}: {task[1]}')

def make_dic(file, term):
    tasks = check_complete(file, term)
    task_dictionary = {i + 1: task for i, task in enumerate(tasks)}
    return task_dictionary, len(task_dictionary)

def add_entry(file, term):
    print(f'{term.clear}')

    task_dictionary, count = make_dic(file, term)
    to_do_list(file, term)

    opt = input('Entry to mark complete.')
    opt = int(opt)
    if opt in task_dictionary:
        task_dictionary[opt][2] = 'True'
    else:
        print('Invalid task number.')
        return

    try:
        with open(file, 'w', encoding='utf-8') as f:
            content = ''
            for i in range(1, count+1):
                for item in task_dictionary[i]:
                    content += f'{item}:'
                content += ','
            f.truncate(0)
            content = content.replace(',', '\n')
            print(content)
            print(file)
            f.write(content)
        print(f'Successfully marked {task_dictionary[opt][1]} as completed.')
    
    except Exception as e:
        print(f'Error: {e}')

    print(task_dictionary[opt])

def mark_undone(file, term):
    print(f'{term.clear}')

    task_dictionary, count = make_dic(file, term)
    to_do_list(file, term)

    opt = input('Entry to mark undone.')
    opt = int(opt)
    if opt in task_dictionary:
        task_dictionary[opt][2] = 'False'
    else:
        print('Invalid task number.')
        return

    try:
        with open(file, 'w', encoding='utf-8') as f:
            content = ''
            for i in range(1, count+1):
                for item in task_dictionary[i]:
                    content += f'{item}:'
                content += ','
            f.truncate(0)
            f.write(f'{content.replace(',', '\n')}')
        print(f'Successfully marked {task_dictionary[opt][1]} as completed.')
        to_do_list(file, term)
    
    except Exception as e:
        print(f'Error: {e}')

    print(task_dictionary[opt])
    
def menu(file, term):
    print(f'{term.clear}{term.white_on_black}')
    file_check(file, term)
    to_do_list(file, term)
    print('''
1) Mark Done
2) Mark Incomplete
3) Exit''')
    opt = input('Selection: ')
    if opt == '1':
        add_entry(file, term)
        menu(file, term)
    elif opt == '2':
        mark_undone(file, term)
        menu(file, term)
    elif opt == '3':
        message = 'BYE BYE!!! xoxo :D <3'
        full_message = ''
        for char in message:
            full_message += color_select(char)
        print(f'{full_message}{term.white_on_black}')
        pass
    else:
        print('Incorrect Option.')
        return

def color_select(char):
    x = random.randrange(1,7)
    colors = {1:term.red,2:term.orange,3:term.yellow,4:term.green,5:term.blue,6:term.light_blue,7:term.purple}
    color = colors[x]
    return f'{color}{char}'

def uncomplete_tasks(line):
    file = '.uncompleted.txt'
    try:
        with open(file, 'r', errors='ignore'):
            pass
    except FileNotFoundError:
            opt = input('Uncompleted tasks file not found. Create file now? (y/n): ')
            if opt.lower() == 'y':
                with open(file, 'w') as f:
                    pass
                print(f'{file} created.')
                try:
                    with open(file, 'w', encoding='utf-8') as f:
                        content = f"{line}\n"
                        print(content)
                        f.write(content)
                except:
                    print(f'Error')
            elif opt.lower() == 'n':
                print('Exiting.')
            else:
                print('Invalid option.')
    except Exception as e:
        print(f'Error: {e}')


# instantiate terminal
term = blessed.Terminal()
file = '/home/jinx/.config/scripts/daily_todo/.todo.txt'

# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('--list', default='0')
args = parser.parse_args()
display_list = args.list

if display_list == '1':
    to_do_list(file, term)
elif display_list == '0':
    file_check(file, term)
    menu(file, term)

Please dont. Just dont…