From 2440f9cb56d1c21c8fee7eacd73c2125f0f9644b Mon Sep 17 00:00:00 2001 From: Julian Pipart Date: Tue, 12 May 2020 10:38:06 +0200 Subject: [PATCH 1/9] update with failures --- ToDoList/ToDo.py | 100 ++++++++++++++++++++++++++++++++++++---------- data/template.csv | 10 +++-- 2 files changed, 84 insertions(+), 26 deletions(-) diff --git a/ToDoList/ToDo.py b/ToDoList/ToDo.py index bdfbdaf..45ea69c 100644 --- a/ToDoList/ToDo.py +++ b/ToDoList/ToDo.py @@ -1,13 +1,16 @@ """ A simple ToDo list """ +import pandas as pd # TODO: -# - read csv -# - write task -# - add a task -# - finish task and remove -# - print tasks +# BUGFIX: +# - status ändert sich bei finish task +# - index bei finish task = -1 + +# - docstring ändern +# - remove task +# - unfish task """ @@ -25,31 +28,84 @@ """ -# TODO dict richtig zurückgeben + def read_data(data_file): - with open(data_file) as f: - f.readline() - data = {} - for line in f: + df = pd.read_csv(data_file, sep=",") + return df + + +""" +Adds a task to the end of the csv file. + +Parameters +---------- +input file: str + +user input: str + +Returns +------- +data file: file + +""" + + +def add_task(df): + new_task = input("Add a new task:\n") + df_mod = df.append({"status": 0, "task": new_task}, ignore_index=True) + csv_mod = df_mod.to_csv("../data/template.csv", index=False) + return csv_mod, output_data(df_mod) + + + +""" +prints the data in the terminal + +Parameters +---------- +input file: str + +Returns +------- +none + +""" + + +def output_data(data): + data_out = data + print("Your tasks:\n") + data_out.loc[(data_out["status"] == 0), ["status"]] = "[ ]" + data_out.loc[(data_out["status"] == 1), ["status"]] = "[X]" + # data_out.index = data_out.index + 1 + print(data_out) + # return data + + +def finish_task(df): + # print(df) + task_to_finish = input("Which task should be finished?: \n") + task_to_finish = df.iloc[int(task_to_finish) - 1] + task_to_finish["status"] = 1 + # print(task_to_finish) + csv_mod = df.to_csv("../data/template.csv", index=False) + return csv_mod - (data["status"], data["task"]) = line.split(";") - # print(f"Your current tasks: \n{input_data}") - print(data) - # return data + # csv_mod = task_to_finish.to_csv("../data/template.csv", index=False) + # return -def add_task(data_file): - with open(data_file, "a") as f: - new_task = input("Add a new task: \n") - new_task_to_append = f"\n[ ] {new_task}" - f.write(new_task_to_append) def main(): test = "../data/template.csv" - read_data(test) - # add_task(test) - # read_data(test) + # data = read_data(test) + data = read_data(test) + test_data = read_data(test) + # print(data) + output_data(data) + # add_task(test_data) + finish_task(data) if __name__ == "__main__": diff --git a/data/template.csv b/data/template.csv index 7cfba1e..1b4d8b9 100644 --- a/data/template.csv +++ b/data/template.csv @@ -1,4 +1,6 @@ -status;task -[ ];this is a test -[ ];fsu fsiufg sfisvb -[ ];gewdf +status,task +1,this is a test +0,fsu fsiufg sfisvb +0,gewdf +1,wgdhjnhgrdsefw +0,fwgehdtdf From 5e9d8b9f914e12c8de809325786d53c95da261e5 Mon Sep 17 00:00:00 2001 From: Julian Pipart Date: Tue, 12 May 2020 10:42:36 +0200 Subject: [PATCH 2/9] update with failures --- ToDoList/ToDo.py | 2 +- data/template.csv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ToDoList/ToDo.py b/ToDoList/ToDo.py index 45ea69c..c0bb33e 100644 --- a/ToDoList/ToDo.py +++ b/ToDoList/ToDo.py @@ -32,7 +32,7 @@ def read_data(data_file): df = pd.read_csv(data_file, sep=",") return df - +# """ Adds a task to the end of the csv file. diff --git a/data/template.csv b/data/template.csv index 1b4d8b9..11f144a 100644 --- a/data/template.csv +++ b/data/template.csv @@ -3,4 +3,4 @@ status,task 0,fsu fsiufg sfisvb 0,gewdf 1,wgdhjnhgrdsefw -0,fwgehdtdf +1,fwgehdtdf From 0403775bb447ff6a9db43d2bbe1d71a2ec6bcaa5 Mon Sep 17 00:00:00 2001 From: Julian Pipart Date: Sat, 16 May 2020 12:19:48 +0200 Subject: [PATCH 3/9] without docstrings --- ToDoList/ToDo.py | 120 ++++++++++++++++++++++++++-------------------- data/template.csv | 21 ++++++-- 2 files changed, 85 insertions(+), 56 deletions(-) diff --git a/ToDoList/ToDo.py b/ToDoList/ToDo.py index c0bb33e..387146a 100644 --- a/ToDoList/ToDo.py +++ b/ToDoList/ToDo.py @@ -4,35 +4,8 @@ import pandas as pd # TODO: -# BUGFIX: -# - status ändert sich bei finish task -# - index bei finish task = -1 - # - docstring ändern -# - remove task -# - unfish task - - -""" -Function for parsing the input file - -Parameters ----------- -input file: str -Returns -------- -dict - ``task`` (str): name of the tasks - ``status`` (int): status if the task is finished or not - -""" - - -def read_data(data_file): - df = pd.read_csv(data_file, sep=",") - return df -# """ Adds a task to the end of the csv file. @@ -52,12 +25,11 @@ def read_data(data_file): def add_task(df): new_task = input("Add a new task:\n") - df_mod = df.append({"status": 0, "task": new_task}, ignore_index=True) + df_mod = df.append({"STATUS": 0, "TASK": new_task}, ignore_index=True) csv_mod = df_mod.to_csv("../data/template.csv", index=False) return csv_mod, output_data(df_mod) - """ prints the data in the terminal @@ -73,39 +45,85 @@ def add_task(df): def output_data(data): - data_out = data + data_out = data.copy() print("Your tasks:\n") - data_out.loc[(data_out["status"] == 0), ["status"]] = "[ ]" - data_out.loc[(data_out["status"] == 1), ["status"]] = "[X]" - # data_out.index = data_out.index + 1 + data_out.loc[(data_out["STATUS"] == 0), ["STATUS"]] = "[ ]" + data_out.loc[(data_out["STATUS"] == 1), ["STATUS"]] = "[X]" + data_out.index = data_out.index + 1 print(data_out) - # return data + return None def finish_task(df): - # print(df) + df_TTF = df task_to_finish = input("Which task should be finished?: \n") - task_to_finish = df.iloc[int(task_to_finish) - 1] - task_to_finish["status"] = 1 - # print(task_to_finish) - csv_mod = df.to_csv("../data/template.csv", index=False) - return csv_mod - - # csv_mod = task_to_finish.to_csv("../data/template.csv", index=False) - # return + df_TTF.loc[[int(task_to_finish) - 1], ["STATUS"]] = 1 + csv_mod = df_TTF.to_csv("../data/template.csv", index=False) + return csv_mod, output_data(df_TTF) + + +def unfinish_task(df): + df_TTF = df + task_to_finish = input("Which task should be unfinished?: \n") + df_TTF.loc[[int(task_to_finish) - 1], ["STATUS"]] = 0 + csv_mod = df_TTF.to_csv("../data/template.csv", index=False) + return csv_mod, output_data(df_TTF) + + +def remove_task(df): + df_TTF = df + task_to_remove = input("Which task should be removed?: \n") + df_TTF = df_TTF.drop(df_TTF.index[int(task_to_remove) - 1]) + df_TTF = df_TTF.reset_index(drop=True) + csv_mod = df_TTF.to_csv("../data/template.csv", index=False) + return csv_mod, output_data(df_TTF) + + +def do_nothing(df): + return print( + r""" + ༼ つ ◕_◕ ༽つ Don't leave me alone! ༼ つ ◕_◕ ༽つ + """ + ) + + +def greeting(): + return r""" + ______ ____ __ __ +/\__ _\ /\ _`\ /\ \ __ /\ \__ +\/_/\ \/ ___\ \ \/\ \ ___\ \ \ /\_\ ____\ \ ,_\ + \ \ \ / __`\ \ \ \ \ / __`\ \ \ __\/\ \ /',__\\ \ \/ + \ \ \/\ \L\ \ \ \_\ \/\ \L\ \ \ \L\ \\ \ \/\__, `\\ \ \_ + \ \_\ \____/\ \____/\ \____/\ \____/ \ \_\/\____/ \ \__\ + \/_/\/___/ \/___/ \/___/ \/___/ \/_/\/___/ \/__/ + +Brought to you by @hugo_weizenkeim and @pipaj97 +""" +def parse_cli(operation, data): + functions = { + "nothing": do_nothing, + "add task": add_task, + "finish task": finish_task, + "unfinish task": unfinish_task, + "remove task": remove_task, + } + if operation in functions: + return functions[operation](data) + else: + print("Wrong input! Try one these:\n") + for key, value in functions.items(): + print(key) def main(): - test = "../data/template.csv" - # data = read_data(test) - data = read_data(test) - test_data = read_data(test) - # print(data) - output_data(data) - # add_task(test_data) - finish_task(data) + data_file = "../data/template.csv" + df = pd.read_csv(data_file, sep=",") + print(greeting()) + output_data(df) + operation = (input("What do you want to do?\n")).lower() + parse_cli(operation, df) if __name__ == "__main__": diff --git a/data/template.csv b/data/template.csv index 11f144a..a9d9732 100644 --- a/data/template.csv +++ b/data/template.csv @@ -1,6 +1,17 @@ -status,task -1,this is a test -0,fsu fsiufg sfisvb +STATUS,TASK 0,gewdf -1,wgdhjnhgrdsefw -1,fwgehdtdf +0,qteh +0,zurjhtfdgr +0,34zu6t +1,ei8lizkujthg +0,8i67uzrte +0,kutrhe +1,richard +0,goikn +1,jhrpotegjrlesömd +0,htedf +0,htdfx +1,"l,zjgmh" +0,wgofplwqmö +1,0 +0,wshrg From 63c0accb590bfc1b61bc61e0d3e9e5fd365f33b8 Mon Sep 17 00:00:00 2001 From: pipaj97 <61475289+pipaj97@users.noreply.github.com> Date: Sat, 16 May 2020 12:46:16 +0200 Subject: [PATCH 4/9] Update ToDo.py --- ToDoList/ToDo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ToDoList/ToDo.py b/ToDoList/ToDo.py index 387146a..c4439da 100644 --- a/ToDoList/ToDo.py +++ b/ToDoList/ToDo.py @@ -112,7 +112,7 @@ def parse_cli(operation, data): if operation in functions: return functions[operation](data) else: - print("Wrong input! Try one these:\n") + print("Wrong input! Try one of these:\n") for key, value in functions.items(): print(key) From 215ee3167cac8e1f2244de9af7e58fa0554d8ebd Mon Sep 17 00:00:00 2001 From: hugo-weizenkeim Date: Sun, 17 May 2020 10:26:28 +0200 Subject: [PATCH 5/9] Docstrings --- ToDoList/ToDo.py | 105 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 21 deletions(-) diff --git a/ToDoList/ToDo.py b/ToDoList/ToDo.py index c4439da..40ff3a8 100644 --- a/ToDoList/ToDo.py +++ b/ToDoList/ToDo.py @@ -7,44 +7,44 @@ # - docstring ändern -""" -Adds a task to the end of the csv file. -Parameters ----------- -input file: str -user input: str -Returns -------- -data file: file +def add_task(df): + """ + Adds a task to the end of the csv file. -""" + Parameters + ---------- + input file: DataFrame + user input: str -def add_task(df): + Returns + ------- + data file: DataFrame + """ new_task = input("Add a new task:\n") df_mod = df.append({"STATUS": 0, "TASK": new_task}, ignore_index=True) csv_mod = df_mod.to_csv("../data/template.csv", index=False) return csv_mod, output_data(df_mod) -""" -prints the data in the terminal -Parameters ----------- -input file: str -Returns -------- -none -""" +def output_data(data): + """ + prints the data in the terminal + Parameters + ---------- + input file: str -def output_data(data): + Returns + ------- + none + """ data_out = data.copy() print("Your tasks:\n") data_out.loc[(data_out["STATUS"] == 0), ["STATUS"]] = "[ ]" @@ -55,6 +55,19 @@ def output_data(data): def finish_task(df): + """ + Labels a task as finished. + + Parameters + ---------- + input file: DataFrame + + user input: str + + Returns + ------- + data file: DataFrame + """ df_TTF = df task_to_finish = input("Which task should be finished?: \n") df_TTF.loc[[int(task_to_finish) - 1], ["STATUS"]] = 1 @@ -63,6 +76,19 @@ def finish_task(df): def unfinish_task(df): + """ + Relabels a finished task as unfinished. + + Parameters + ---------- + input file: DataFrame + + user input: str + + Returns + ------- + data file: DataFrame + """ df_TTF = df task_to_finish = input("Which task should be unfinished?: \n") df_TTF.loc[[int(task_to_finish) - 1], ["STATUS"]] = 0 @@ -71,6 +97,19 @@ def unfinish_task(df): def remove_task(df): + """ + Removes a task from the ToDo list. + + Parameters + ---------- + input file: DataFrame + + user input: str + + Returns + ------- + data file: DataFrame + """ df_TTF = df task_to_remove = input("Which task should be removed?: \n") df_TTF = df_TTF.drop(df_TTF.index[int(task_to_remove) - 1]) @@ -80,6 +119,17 @@ def remove_task(df): def do_nothing(df): + """ + Enables not to change the ToDo list. + + Parameters + ---------- + input file: DataFrame + + Returns + ------- + data file: str + """ return print( r""" ༼ つ ◕_◕ ༽つ Don't leave me alone! ༼ つ ◕_◕ ༽つ @@ -102,6 +152,19 @@ def greeting(): def parse_cli(operation, data): + """ + User input activates specific function. + + Parameters + ---------- + input file: str + + user input: str + + Returns + ------- + chosen function + """ functions = { "nothing": do_nothing, "add task": add_task, From 987247e4d10e271d3346fd06b74d128e56430adf Mon Sep 17 00:00:00 2001 From: Julian Pipart Date: Thu, 21 May 2020 14:08:38 +0200 Subject: [PATCH 6/9] a lot of changes --- ToDoList/ToDo.py | 317 +++++++++++++++++++++-------------------------- ToDoList/cli.py | 132 ++++++++++++++++++++ 2 files changed, 273 insertions(+), 176 deletions(-) diff --git a/ToDoList/ToDo.py b/ToDoList/ToDo.py index 40ff3a8..0899cf4 100644 --- a/ToDoList/ToDo.py +++ b/ToDoList/ToDo.py @@ -3,142 +3,18 @@ """ import pandas as pd -# TODO: -# - docstring ändern - - - - - -def add_task(df): - """ - Adds a task to the end of the csv file. - - Parameters - ---------- - input file: DataFrame - - user input: str - - Returns - ------- - data file: DataFrame - """ - new_task = input("Add a new task:\n") - df_mod = df.append({"STATUS": 0, "TASK": new_task}, ignore_index=True) - csv_mod = df_mod.to_csv("../data/template.csv", index=False) - return csv_mod, output_data(df_mod) - - - - - -def output_data(data): - """ - prints the data in the terminal - - Parameters - ---------- - input file: str - - Returns - ------- - none - """ - data_out = data.copy() - print("Your tasks:\n") - data_out.loc[(data_out["STATUS"] == 0), ["STATUS"]] = "[ ]" - data_out.loc[(data_out["STATUS"] == 1), ["STATUS"]] = "[X]" - data_out.index = data_out.index + 1 - print(data_out) - return None - - -def finish_task(df): - """ - Labels a task as finished. - - Parameters - ---------- - input file: DataFrame - - user input: str - - Returns - ------- - data file: DataFrame - """ - df_TTF = df - task_to_finish = input("Which task should be finished?: \n") - df_TTF.loc[[int(task_to_finish) - 1], ["STATUS"]] = 1 - csv_mod = df_TTF.to_csv("../data/template.csv", index=False) - return csv_mod, output_data(df_TTF) - - -def unfinish_task(df): - """ - Relabels a finished task as unfinished. - - Parameters - ---------- - input file: DataFrame - - user input: str - - Returns - ------- - data file: DataFrame - """ - df_TTF = df - task_to_finish = input("Which task should be unfinished?: \n") - df_TTF.loc[[int(task_to_finish) - 1], ["STATUS"]] = 0 - csv_mod = df_TTF.to_csv("../data/template.csv", index=False) - return csv_mod, output_data(df_TTF) - - -def remove_task(df): - """ - Removes a task from the ToDo list. - - Parameters - ---------- - input file: DataFrame - - user input: str - - Returns - ------- - data file: DataFrame +class ToDo: """ - df_TTF = df - task_to_remove = input("Which task should be removed?: \n") - df_TTF = df_TTF.drop(df_TTF.index[int(task_to_remove) - 1]) - df_TTF = df_TTF.reset_index(drop=True) - csv_mod = df_TTF.to_csv("../data/template.csv", index=False) - return csv_mod, output_data(df_TTF) - - -def do_nothing(df): - """ - Enables not to change the ToDo list. - - Parameters - ---------- - input file: DataFrame - - Returns - ------- - data file: str - """ - return print( - r""" - ༼ つ ◕_◕ ༽つ Don't leave me alone! ༼ つ ◕_◕ ༽つ + Driver class for the functionality of the ToDo list. """ - ) - - -def greeting(): - return r""" + def __init__(self): + self.data_file = "/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv" + self.df = pd.read_csv(self.data_file, sep=",") + print(self.greeting()) + self.output_data(self.df) + + def greeting(self): + return r""" ______ ____ __ __ /\__ _\ /\ _`\ /\ \ __ /\ \__ \/_/\ \/ ___\ \ \/\ \ ___\ \ \ /\_\ ____\ \ ,_\ @@ -147,47 +23,136 @@ def greeting(): \ \_\ \____/\ \____/\ \____/\ \____/ \ \_\/\____/ \ \__\ \/_/\/___/ \/___/ \/___/ \/___/ \/_/\/___/ \/__/ -Brought to you by @hugo_weizenkeim and @pipaj97 -""" + Brought to you by @pipaj97 and @hugo_weizenkeim + """ -def parse_cli(operation, data): - """ - User input activates specific function. - - Parameters - ---------- - input file: str - - user input: str - - Returns - ------- - chosen function - """ - functions = { - "nothing": do_nothing, - "add task": add_task, - "finish task": finish_task, - "unfinish task": unfinish_task, - "remove task": remove_task, - } - if operation in functions: - return functions[operation](data) - else: - print("Wrong input! Try one of these:\n") - for key, value in functions.items(): - print(key) - - -def main(): - data_file = "../data/template.csv" - df = pd.read_csv(data_file, sep=",") - print(greeting()) - output_data(df) - operation = (input("What do you want to do?\n")).lower() - parse_cli(operation, df) - - -if __name__ == "__main__": - main() + def output_data(self, df): + """ + Prints the data in the terminal. + + Parameters + ---------- + input file: str + + Returns + ------- + none + """ + data_out = df.copy() + if data_out.empty: + print("There are no tasks.\n") + else: + print("Your tasks:\n") + data_out.loc[(data_out["STATUS"] == 0), ["STATUS"]] = "[ ]" + data_out.loc[(data_out["STATUS"] == 1), ["STATUS"]] = "[X]" + data_out.index = data_out.index + 1 + print(data_out) + return None + + + def add_task(self): + """ + Adds a task to the end of the csv file. + + Parameters + ---------- + input file: DataFrame + + user input: str + + Returns + ------- + data file: DataFrame + """ + new_task = input("Add a new task:\n") + if new_task == "": + print("Wrong input!") + return self.output_data(self.df) + else: + df_mod = self.df.append({"STATUS": 0, "TASK": new_task}, ignore_index=True) + csv_mod = df_mod.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) + return csv_mod, self.output_data(df_mod) + + + def finish_task(self, chosen_task): + """ + Labels a task as finished. + + Parameters + ---------- + input file: DataFrame + + user input: str + + Returns + ------- + data file: DataFrame + """ + df_TTF = self.df + task_to_finish = chosen_task + df_TTF.loc[df_TTF["TASK"] == chosen_task, ["STATUS"]] = 1 + csv_mod = df_TTF.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) + return csv_mod, self.output_data(df_TTF) + + + def unfinish_task(self, chosen_task): + """ + Relabels a finished task as unfinished. + + Parameters + ---------- + input file: DataFrame + + user input: str + + Returns + ------- + data file: DataFrame + """ + df_TTU = self.df + task_to_finish = chosen_task + df_TTU.loc[df_TTU["TASK"] == chosen_task, ["STATUS"]] = 0 + csv_mod = df_TTU.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) + return csv_mod, self.output_data(df_TTU) + + + def remove_task(self, chosen_task): + """ + Removes a task from the ToDo list. + + Parameters + ---------- + input file: DataFrame + + user input: str + + Returns + ------- + data file: DataFrame + """ + df_TTR = self.df + task_to_remove = chosen_task + df_TTR = df_TTR.drop(df_TTR[df_TTR["TASK"] == chosen_task].index) + new_df_TTR = df_TTR.reset_index(drop=True) + csv_mod = new_df_TTR.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) + return csv_mod, self.output_data(new_df_TTR) + + + def exit(self): + """ + Enables not to change the ToDo list. + + Parameters + ---------- + input file: DataFrame + + Returns + ------- + data file: str + """ + return print( + r""" +༼ つ ◕_◕ ༽つ Don't leave me alone! ༼ つ ◕_◕ ༽つ + """ + ) diff --git a/ToDoList/cli.py b/ToDoList/cli.py index e69de29..a6cfe8d 100644 --- a/ToDoList/cli.py +++ b/ToDoList/cli.py @@ -0,0 +1,132 @@ +# -*- coding: utf-8 -*- +""" +simple cli for the ToDo list +""" + +from PyInquirer import style_from_dict, prompt +from examples import custom_style_2, custom_style_1 +from ToDo import ToDo +import pandas as pd + +# TODO: +# manchmal bricht es einfach ab? +# docstrings hinzufügen und in TODO.py ändern +# windows support +# setup.py +# datafile in __init__ ändern + + +def ask_operation(liste): + if liste.df.empty: + operation_prompt = { + 'type': 'list', + 'name': 'operation', + 'message': 'What do you want to do?', + 'choices': ['add task', 'exit'] + } + else: + operation_prompt = { + 'type': 'list', + 'name': 'operation', + 'message': 'What do you want to do?', + 'choices': ['add task', 'finish task', 'unfinish task', 'remove task', 'exit'] + } + answers = prompt(operation_prompt, style=custom_style_2) + return answers['operation'] + +def ask_task(series): + tasks = [ + { + 'type': 'list', # raw list geht nur bis 9 --> zu list gewechselt + 'name': 'tasks', + 'message': 'Choose a task!', + 'choices': series + } + ] + tasks = prompt(tasks, style=custom_style_2) + return tasks["tasks"] + +def ask_permission(): + questions = { + 'type': 'confirm', + 'message': 'Do you really want to remove that task?', + 'name': 'continue', + 'default': True + } + answers = prompt(questions, style=custom_style_1) + return answers + + + + +def parse_answer(liste): + operation = ask_operation(liste) + switch_case = { + 'add task' : c_add_task, + 'finish task' : c_finish_task, + 'unfinish task' : c_unfinished_task, + 'remove task' : c_remove_task, + 'exit' : c_exit + } + + func = switch_case.get(operation) + func(liste) + + +def c_exit(liste): + return liste.exit() + +def c_add_task(liste): + liste.add_task() + liste.df = pd.read_csv(liste.data_file, sep=",") + return parse_answer(liste) + +def c_finish_task(liste): + relevant_tasks = liste.df.loc[(liste.df["STATUS"] == 0)] + series = relevant_tasks["TASK"].tolist() + if len(series) == 0: + print("No unfinished tasks available!\n") + return parse_answer(liste) + else: + chosen_task = ask_task(series) + liste.finish_task(chosen_task) + return parse_answer(liste) + +def c_unfinished_task(liste): + relevant_tasks = liste.df.loc[(liste.df["STATUS"] == 1)] + series = relevant_tasks["TASK"].tolist() + if len(series) == 0: + print("No finished tasks available!\n") + return parse_answer(liste) + else: + chosen_task = ask_task(series) + liste.unfinish_task(chosen_task) + return parse_answer(liste) + +def c_remove_task(liste): + series = liste.df["TASK"].tolist() + chosen_task = ask_task(series) + row = liste.df.loc[(liste.df["TASK"] == chosen_task)] + status = row["STATUS"].values + if (status[0] == 0): + permission = ask_permission() + if permission["continue"] == True: + liste.remove_task(chosen_task) + liste.df = pd.read_csv(liste.data_file, sep=",") + return parse_answer(liste) + else: + liste.output_data(liste.df) + return parse_answer(liste) + else: + liste.remove_task(chosen_task) + liste.df = pd.read_csv(liste.data_file, sep=",") + return parse_answer(liste) + + +def main(): + liste = ToDo() + parse_answer(liste) + + +if __name__ == '__main__': + main() \ No newline at end of file From d32d11b9e27b0c96c93cc20035e4b2894b555751 Mon Sep 17 00:00:00 2001 From: Julian Pipart Date: Sun, 24 May 2020 16:54:34 +0200 Subject: [PATCH 7/9] Setup for package --- MANIFEST.in | 1 + ToDoList/__init__.py | 8 ++++++++ data/template.csv | 17 +---------------- setup.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 MANIFEST.in create mode 100644 ToDoList/__init__.py create mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e7ad219 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include data/template.csv \ No newline at end of file diff --git a/ToDoList/__init__.py b/ToDoList/__init__.py new file mode 100644 index 0000000..bec5a59 --- /dev/null +++ b/ToDoList/__init__.py @@ -0,0 +1,8 @@ +import os +import ToDoList + +src = os.path.join(os.path.dirname(ToDoList.__file__), 'data/template.csv') + +def get(): + with open(src) as f: + return f.read().strip() \ No newline at end of file diff --git a/data/template.csv b/data/template.csv index a9d9732..a4068c3 100644 --- a/data/template.csv +++ b/data/template.csv @@ -1,17 +1,2 @@ STATUS,TASK -0,gewdf -0,qteh -0,zurjhtfdgr -0,34zu6t -1,ei8lizkujthg -0,8i67uzrte -0,kutrhe -1,richard -0,goikn -1,jhrpotegjrlesömd -0,htedf -0,htdfx -1,"l,zjgmh" -0,wgofplwqmö -1,0 -0,wshrg +1,test1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..dc67bd5 --- /dev/null +++ b/setup.py @@ -0,0 +1,31 @@ +import sys +from setuptools import setup, find_packages + +setup( + # Self-descriptive entries which should always be present + name="ToDoList", + author="pipaj97", + author_email="julian.pipart@fu-berlin.de", + # Which Python importable modules should be included when your package is installed + # Handled automatically by setuptools. Use 'exclude' to prevent some specific + # subpackage(s) from being added, if needed + packages=find_packages(), + # package_data={"" : ["template.csv"]}, + # Optional include package data to ship with your package + # Customize MANIFEST.in if the general case does not suit your needs + # Comment out this line to prevent the files from being packaged with your software + include_package_data=True, + # Entry point + entry_points={"console_scripts": ["ToDo = ToDoList.cli:main"]}, + # Allows `setup.py test` to work correctly with pytest + # Additional entries you may want simply uncomment the lines you want and fill in the data + # url='http://www.my_package.com', # Website + # install_requires=[], # Required packages, pulls from pip if needed; do not use for Conda deployment + # platforms=['Linux', + # 'Mac OS-X', + # 'Unix', + # 'Windows'], # Valid platforms your code works on, adjust to your flavor + # python_requires=">=3.5", # Python version restrictions + # Manual control if final package is compressible or not, set False to prevent the .egg from being made + # zip_safe=False, +) \ No newline at end of file From b0668555a41aa9ecb78230546922f4a9852ac97c Mon Sep 17 00:00:00 2001 From: Julian Pipart Date: Sun, 24 May 2020 16:55:11 +0200 Subject: [PATCH 8/9] greeting and exit and docstrings --- ToDoList/cli.py | 61 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/ToDoList/cli.py b/ToDoList/cli.py index a6cfe8d..da410d1 100644 --- a/ToDoList/cli.py +++ b/ToDoList/cli.py @@ -5,18 +5,18 @@ from PyInquirer import style_from_dict, prompt from examples import custom_style_2, custom_style_1 -from ToDo import ToDo +from .ToDo import ToDo import pandas as pd # TODO: # manchmal bricht es einfach ab? -# docstrings hinzufügen und in TODO.py ändern +# docstrings hinzufügen # windows support -# setup.py -# datafile in __init__ ändern +# tests hinzufügen def ask_operation(liste): + print("\n") if liste.df.empty: operation_prompt = { 'type': 'list', @@ -60,23 +60,33 @@ def ask_permission(): def parse_answer(liste): + """ + + """ operation = ask_operation(liste) switch_case = { 'add task' : c_add_task, 'finish task' : c_finish_task, 'unfinish task' : c_unfinished_task, 'remove task' : c_remove_task, - 'exit' : c_exit + 'exit' : exit } func = switch_case.get(operation) func(liste) - -def c_exit(liste): - return liste.exit() - def c_add_task(liste): + """ + Calls the add_task method of liste. + Parameters + ---------- + liste: ToDo() + Instance of the ToDo class. + + Returns + ------- + parse_answer(liste): func + """ liste.add_task() liste.df = pd.read_csv(liste.data_file, sep=",") return parse_answer(liste) @@ -122,10 +132,43 @@ def c_remove_task(liste): liste.df = pd.read_csv(liste.data_file, sep=",") return parse_answer(liste) +def greeting(): + """Greets the user of the command line interface.""" + return r""" + ______ ____ __ __ +/\__ _\ /\ _`\ /\ \ __ /\ \__ +\/_/\ \/ ___\ \ \/\ \ ___\ \ \ /\_\ ____\ \ ,_\ + \ \ \ / __`\ \ \ \ \ / __`\ \ \ __\/\ \ /',__\\ \ \/ + \ \ \/\ \L\ \ \ \_\ \/\ \L\ \ \ \L\ \\ \ \/\__, `\\ \ \_ + \ \_\ \____/\ \____/\ \____/\ \____/ \ \_\/\____/ \ \__\ + \/_/\/___/ \/___/ \/___/ \/___/ \/_/\/___/ \/__/ + + Brought to you by @pipaj97 and @hugo_weizenkeim + """ + +def exit(liste): + """ + Enables not to change the ToDo list. + + Parameters + ---------- + liste: ToDo() + Instance of the ToDo class. + + Returns + ------- + raw str + """ + return r""" +༼ つ ◕_◕ ༽つ Don't leave me alone! ༼ つ ◕_◕ ༽つ + """ + def main(): + print(greeting()) liste = ToDo() parse_answer(liste) + print(exit(liste)) if __name__ == '__main__': From d5c435803fbde60a195e33b87d3a5da7562bd3cf Mon Sep 17 00:00:00 2001 From: Julian Pipart Date: Sun, 24 May 2020 16:55:48 +0200 Subject: [PATCH 9/9] dynamic path and docstrings --- ToDoList/ToDo.py | 105 ++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 61 deletions(-) diff --git a/ToDoList/ToDo.py b/ToDoList/ToDo.py index 0899cf4..db339d7 100644 --- a/ToDoList/ToDo.py +++ b/ToDoList/ToDo.py @@ -2,42 +2,35 @@ A simple ToDo list """ import pandas as pd +from pathlib import Path class ToDo: """ Driver class for the functionality of the ToDo list. """ def __init__(self): - self.data_file = "/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv" + + self.data_file = self.get_path() self.df = pd.read_csv(self.data_file, sep=",") - print(self.greeting()) self.output_data(self.df) - def greeting(self): - return r""" - ______ ____ __ __ -/\__ _\ /\ _`\ /\ \ __ /\ \__ -\/_/\ \/ ___\ \ \/\ \ ___\ \ \ /\_\ ____\ \ ,_\ - \ \ \ / __`\ \ \ \ \ / __`\ \ \ __\/\ \ /',__\\ \ \/ - \ \ \/\ \L\ \ \ \_\ \/\ \L\ \ \ \L\ \\ \ \/\__, `\\ \ \_ - \ \_\ \____/\ \____/\ \____/\ \____/ \ \_\/\____/ \ \__\ - \/_/\/___/ \/___/ \/___/ \/___/ \/_/\/___/ \/__/ - - Brought to you by @pipaj97 and @hugo_weizenkeim - """ + def get_path(self): + base_path = Path(__file__).parent + file_path = (base_path / "../data/template.csv").resolve() + return file_path def output_data(self, df): """ - Prints the data in the terminal. + Prints the DataFrame in the terminal. Parameters ---------- - input file: str + input file: DataFrame Returns ------- - none + None """ data_out = df.copy() if data_out.empty: @@ -57,13 +50,19 @@ def add_task(self): Parameters ---------- - input file: DataFrame - - user input: str + None Returns ------- - data file: DataFrame + If no user input is given: + self.output_data(self.df): func + Function to display the updated DataFrame. + + Else: + csv_mod: CSV + Updated CSV file. + self.output_data(df_mod): func + Function to display the updated DataFrame. """ new_task = input("Add a new task:\n") if new_task == "": @@ -71,7 +70,7 @@ def add_task(self): return self.output_data(self.df) else: df_mod = self.df.append({"STATUS": 0, "TASK": new_task}, ignore_index=True) - csv_mod = df_mod.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) + csv_mod = df_mod.to_csv(self.data_file, index=False) return csv_mod, self.output_data(df_mod) @@ -81,39 +80,41 @@ def finish_task(self, chosen_task): Parameters ---------- - input file: DataFrame - - user input: str + chosen_task: dict of {str: str} + The chosen task which will be labelled as finished. Returns ------- - data file: DataFrame + csv_mod: CSV + Updated CSV file. + self.output_data(df_TTF): func + Function to display the updated DataFrame. """ df_TTF = self.df - task_to_finish = chosen_task df_TTF.loc[df_TTF["TASK"] == chosen_task, ["STATUS"]] = 1 - csv_mod = df_TTF.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) + csv_mod = df_TTF.to_csv(self.data_file, index=False) return csv_mod, self.output_data(df_TTF) def unfinish_task(self, chosen_task): """ - Relabels a finished task as unfinished. + Labels a task as unfinished. Parameters ---------- - input file: DataFrame - - user input: str + chosen_task: dict of {str: str} + The chosen task which will be labelled as unfinished. Returns ------- - data file: DataFrame + csv_mod: CSV + Updated CSV file. + self.output_data(df_TTU): func + Function to display the updated DataFrame. """ df_TTU = self.df - task_to_finish = chosen_task df_TTU.loc[df_TTU["TASK"] == chosen_task, ["STATUS"]] = 0 - csv_mod = df_TTU.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) + csv_mod = df_TTU.to_csv(self.data_file, index=False) return csv_mod, self.output_data(df_TTU) @@ -123,36 +124,18 @@ def remove_task(self, chosen_task): Parameters ---------- - input file: DataFrame - - user input: str + chosen_task: dict of {str: str} + The chosen task which will be removed. Returns ------- - data file: DataFrame + csv_mod: CSV + Updated CSV file. + self.output_data(new_df_TTR): func + Function to display the updated DataFrame. """ df_TTR = self.df - task_to_remove = chosen_task df_TTR = df_TTR.drop(df_TTR[df_TTR["TASK"] == chosen_task].index) new_df_TTR = df_TTR.reset_index(drop=True) - csv_mod = new_df_TTR.to_csv("/home/julian/PythonProjects/MyProjects/ToDoList/data/template.csv", index=False) - return csv_mod, self.output_data(new_df_TTR) - - - def exit(self): - """ - Enables not to change the ToDo list. - - Parameters - ---------- - input file: DataFrame - - Returns - ------- - data file: str - """ - return print( - r""" -༼ つ ◕_◕ ༽つ Don't leave me alone! ༼ つ ◕_◕ ༽つ - """ - ) + csv_mod = new_df_TTR.to_csv(self.data_file, index=False) + return csv_mod, self.output_data(new_df_TTR) \ No newline at end of file