-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.py
107 lines (81 loc) · 2.21 KB
/
project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Project Title: Programming Journal
Author: Shawn
Location: Kansas City, Missouri, USA
"""
import json
import random
import sys
# import os
from datetime import date
from datamanager import DataManager
def main():
"""Loop program until user exits
:return: None
"""
print("\n---Welcome to your programming journal---")
while True:
display_menu()
get_user_choice()
def display_menu():
"""Display menu of user choices
:return: None
"""
print(
"""
What do you want to do?
1. New journal entry
2. Search all entries
3. Read all entries
4. Exit
"""
)
def get_user_choice():
"""Get user's entry from menu choices and call assigned functions
:return: None
"""
user_input = input("Make your choice: ")
# os.system('clear')
match user_input:
case "1":
user_entry = input("\nWhat did you learn today? \n")
dm.insert_entry(date=date.today(), entry=user_entry)
case "2":
user_query = input("\nEnter search term: ")
search_results = dm.search_entries(query=user_query)
display_entries(entries=search_results)
case "3":
all_entries = dm.select_all_entries()
display_entries(entries=all_entries)
case "4":
quote = get_quote()
sys.exit(f"\n{quote['text']}\n"
f"--{quote['author']}\n\n")
case _:
print("Please enter a valid selection.")
return 0
def get_quote():
"""Load a funny quote about programming from a JSON file
:return: dict of quote: author
"""
with open('quotes.json') as fin:
data = json.load(fin)
quote = random.choice(data)
return quote
def display_entries(entries):
"""Display entries from journal database
:param entries: list of dates, journal entries
:return: None
"""
print(entries)
print(type(entries))
if entries:
for row in entries:
print(f"\n{row[0]}\n")
print(f"{row[1]}\n")
else:
print()
print("No entries found")
if __name__ == "__main__":
dm = DataManager()
main()