-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
154 lines (120 loc) · 4.16 KB
/
main.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# imports
from cli_tables.cli_tables import *
import time
import re
import csv
import os
# Create new table
def create_new_table():
time.sleep(0.1)
print("- You have chosen to create a new table -")
table_file_name = input("Table name : ")
OUTPUT_DIR = os.getcwd()
f_path = open(os.path.join(OUTPUT_DIR, f'{table_file_name}.csv'), 'w')
f_path.close()
width = int(input("How many days do you want to track use this table ? :"))
string_habits = input(
"Please enter a list of habits, seperated by a comma : ")
list_habits = string_habits.split(',')
# creating the header - can be thought of as the fields
header = ['Habits']
for i in range(1, width+1):
header.append(f"Day {i}")
# creating records
data = []
for habit in list_habits:
data.append([habit])
for i in range(len(list_habits)):
for j in range(width):
data[i].append(' ')
# writing data and header to path
string_full_path = os.path.join(OUTPUT_DIR, f'{table_file_name}.csv')
with open(string_full_path, 'w') as work:
z = csv.writer(work)
z.writerow(header)
z.writerows(data)
print(f"- creation of the {table_file_name} table successful-")
# Delete a table
def delete_table():
time.sleep(0.1)
print("- You have chosen to delete a table -")
table_file_name = input("Enter table name, to remove : ")
path = os.getcwd()
directories = os.listdir(path) # list of file names
for file in directories:
match = re.search("\.csv$", file)
if match:
full_path = os.path.join(path, file)
os.remove(full_path)
def display_table(): # Currently working on
print("- you have chosen to display a table -")
table_name = input("Please enter your table name : ")
print("You have choose multiple views :")
print("For GUI(pretty) view select: 1")
print("For CLI(normal) view select: 2")
choice = int(input())
if choice == 1:
pass # to do
else:
try:
file_csv = open(f"{table_name}.csv")
except:
print("error - no table of that name found ")
pass
data_csv = csv.reader(file_csv)
list_csv = list(data_csv)
table_list = [x for x in list_csv if x]
print_table(table_list, double_hline=True, double_vline=True)
def update_table():
print("- you have chosen to update one of your tables -")
table_name = input("Please enter your table name : ")
# display a list of habits that they have, with some given indices so
# that choosing a habit to update will be easier
try:
file_csv = open(f"{table_name}.csv")
except:
print("error - no table of that name found ")
pass
data_csv = csv.reader(file_csv)
list_csv = list(data_csv)
table_list = [x for x in list_csv if x]
table_list.pop(0)
habits = []
for lists in table_list:
habits.append([f" {lists[0]} "])
for i in range(1, len(habits) + 1):
habits[i-1].append(f" {str(i)} ")
habits.insert(0, ["Habit", "Index"])
print("Here are the habits in your table : ")
print_table(habits, double_vline=True, double_hline=True)
index_chosen = int(input("Please choose : "))
chosen = habits[index_chosen - 1]
for habit in table_list:
if habit == chosen:
pass
# main
def main():
print("Let's get started, welcome to the habit tracker")
time.sleep(0.5)
want_to_continue = input("Start program [Y/n] ")
while want_to_continue.lower() != 'n':
print("Options : ")
print("Update your habit 😄 : 1")
print("View habit tables 😋 : 2")
print("Create a new habit table 😌 : 3")
print("Delete a table 😊 : 4")
try:
choice = int(input())
except:
print("Error - no 'valid' choice chosen")
if choice == 1:
update_table()
elif choice == 2:
display_table()
elif choice == 3:
create_new_table()
elif choice == 4:
delete_table()
want_to_continue = input("Continue [Y/n] ")
if __name__ == "__main__":
main()