Browse Source

works with new data structure, added show function

master
hejo 2 years ago
parent
commit
66895920b9
  1. 36
      butly.py

36
butly.py

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
import yaml
import sys
import datetime
from datetime import date
import random #for the quiz
@ -7,9 +8,8 @@ today = date.today() @@ -7,9 +8,8 @@ today = date.today()
# FUNCTION - ADD TO DATABASE
def add_task(task, due, cat, recur):
temp_id = max(cal)+1
temp_cont = {'task': task, 'due': due, 'cat': cat, 'recur': recur}
cal[temp_id] = temp_cont
cal.append(temp_cont)
return print("Added " + task + " to the database!")
# FUNCTION - SHOW CATEGORIES
@ -40,33 +40,31 @@ categories = ['Reminder','Meeting','Birthday'] @@ -40,33 +40,31 @@ categories = ['Reminder','Meeting','Birthday']
# Frequency
freq = ['Once','Daily','Weekly','Yearly']
# IMPORT YAML FILE
with open(r'cal.yaml') as file:
cal = yaml.load(file, Loader=yaml.FullLoader)
# RAW OUTPUT
print(cal)
cal.sort(key=lambda item: item.get('due'))
# ADD ENTRY
in_task = input('What is the task?\n')
in_due = input('When is it due? ISO format\n')
## Frequency
print('What is the frequency?\n')
show_list(freq)
in_recur = item_from_list(freq)
## ADD CATEGORIES
print('What is the category?\n')
show_list(categories)
in_cat = item_from_list(categories)
if len(sys.argv) == 1 or sys.argv[1] == "show":
for i in cal:
print(f"{i['task']} on the {i['due']}")
# ------ ADD ENTRY ------
elif sys.argv[1] == "add":
in_task = input('What is the task?\n')
in_due = input('When is it due? ISO format\n')
print('What is the frequency?\n')
show_list(freq)
in_recur = item_from_list(freq)
print('What is the category?\n')
show_list(categories)
in_cat = item_from_list(categories)
add_task(in_task,in_due,in_cat,in_recur)
add_task(in_task,in_due,in_cat,in_recur)
# RAW OUTPUT
print(cal)

Loading…
Cancel
Save