-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.py
More file actions
139 lines (122 loc) · 4.54 KB
/
App.py
File metadata and controls
139 lines (122 loc) · 4.54 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# this handles saving and loading of files
from fileHandler import *
import time
import datetime
# Functions used within other functions
# takes input from a list of books and prints a list to choose from
def list_books(book_list, add_page_count_target=False):
if not add_page_count_target:
# creates a readable and selectable list of books passed from the database query
for count, value in enumerate(book_list):
current_book = f"{value[1]} by {value[2]}"
print(f"{count + 1}. {current_book}")
else:
# adds page count target
for count, value in enumerate(book_list):
length = value[3]
target_date = value[4]
position = value[6]
today = int(datetime.datetime.now().timestamp())
pages_left = length - position
days_left = int((target_date - today) / 86400) # 86400 is the number of seconds in a day
pages_per_day = int(pages_left / days_left)
current_book = f'{value[1]} by {value[2]} -\t- read {pages_per_day} pages per day to meet your target'
print(f"{count + 1}. {current_book}")
# function for listing all books with full info
def list_all_books():
current = load_all()
list_books(current)
# lists only the titles and author, used for making a list of books to choose from
def list_current_titles(add_page_count_target=False):
current = load_current()
if add_page_count_target:
list_books(current, add_page_count_target)
else:
list_books(current)
# lists all finished books
def list_finished():
current = load_finished()
list_books(current)
# Overarching functions for parts of the main menu
# function for starting a new book
def new_book():
book = [
input("please enter a title: "),
input("please enter the author's name: "),
int(input("Please enter the number of pages: "))
]
print("Please enter the target date")
year = int(input('Enter a year'))
month = int(input('Enter a month'))
day = int(input('Enter a day'))
date = f"{day}/{month}/{year}"
date = datetime.datetime.strptime(date, "%d/%m/%Y")
date = date.timetuple()
date = time.mktime(date)
book.append(int(date))
book.append(str(True))
book.append(0)
book = tuple(map(str, book))
save(book)
def add_position():
current_books = load_current()
entered_position = False
while not entered_position:
print("Please choose a title:")
list_current_titles(True)
selection = int(0)
try:
selection = int(input())
if len(current_books) >= selection > 0:
selection = selection - 1
this_book = current_books[selection]
while True:
page_num = int(input("What page are you currently on?\n"))
if this_book[4] > page_num > 0:
rowid = str(current_books[selection][0])
add_new_position(rowid, page_num)
entered_position = True
break
elif page_num == this_book["length"]:
print("Congratulations, you've finished!")
rowid = str(current_books[selection][0])
change_to_complete(rowid)
entered_position = True
break
elif page_num == 0:
break
else:
print("Please enter a valid page number")
break
elif selection == 0:
break
else:
print("Please enter a number corresponding with the books on the list")
except:
print("Please enter a number")
# main menu
def main_menu():
stay = True
choice = int(0)
while stay:
choice = int(0)
try:
print("\nWould you like to: ")
print("1.Start a new book")
print("2.Add a new page position to a book you're reading")
print("3.View stats on a previously read book?")
choice = input()
choice = int(choice)
if choice == 1:
new_book()
elif choice == 2:
add_position()
elif choice == 3:
pass
elif choice == 0:
stay = False
except:
if choice == 'exit':
break
print("\n\n!Please enter a number between 1 and 3!")
main_menu()