def remove(self): """ """ print("remove") # Show the exams available self.mode_run("Show") # * Ask user fo the class code and the date of the exams id = self.id_input() # Confirmation question confirmation = [{ 'type': 'confirm', 'message': 'Are you sure you want to remove exam ?', 'name': 'confirm', 'default': False, }] confirmation_answer = prompt(confirmation, style=custom_style_1) if confirmation_answer['confirm'] == True: # Connect to a database -> if does not exist -> create conn = create_connection(self.database) # Delete the exam with given id delete_exam(conn, id) # Saves the changes you made and quit conn.commit() conn.close() else: print("Operation Canceled.")
def record_study_time(self, itemClass): """ starts a stopwatch and records the time, when the users stop it -> appends the time to the exam """ # Ask the user for the exam they want to record tihe study time id = self.id_input() # Start the stopwatch currentTime = stopwatch() currentTime = datetime.timedelta( seconds=round(currentTime)) # convert float to time obj # Retrieve the study time of the given id conn = create_connection(itemClass.databaseFile) # Get the studyTime data = get_item_attribute(conn, itemClass, "studyTime", id) # Constructing the datetime.time obj from string retrievedTime = datetime.datetime.strptime(str(data), '%H:%M:%S').time() retrievedTime = datetime.timedelta( hours=retrievedTime.hour, minutes=retrievedTime.minute, seconds=retrievedTime.second) # converting the time to timedelta # Appending the time totalTime = str((currentTime + retrievedTime)) # Updating the database set_item_attribute(conn, itemClass, "studyTime", totalTime, id) # Closing the database conn.commit() conn.close()
def record_study_time(self): """ starts a stopwatch and records the time, when the users stop it -> appends the time to the exam """ # Show the exams available self.mode_run("Show") # Ask the user for the exam they want to record tihe study time id = self.id_input() # Start the stopwatch currentTime = stopwatch() currentTime = datetime.timedelta( seconds=round(currentTime)) # convert float to time obj # Retrieve the study time of the given id conn = create_connection(self.database) cur = conn.cursor() sql = ''' SELECT studyTime FROM exams WHERE id=? ''' cur.execute(sql, (id, )) data = cur.fetchone() # Constructing the datetime.time obj from string retrievedTime = datetime.datetime.strptime(data[0], '%H:%M:%S').time() retrievedTime = datetime.timedelta( hours=retrievedTime.hour, minutes=retrievedTime.minute, seconds=retrievedTime.second) # converting the time to timedelta # Appending the time totalTime = str((currentTime + retrievedTime)) # Updating the database sql = ''' UPDATE exams SET studyTime = ? WHERE id = ?''' cur.execute(sql, (totalTime, id)) # Closing the database conn.commit() conn.close()
def show(self): """ """ print("show") # Fetch all the exams from the database conn = create_connection(self.database) cur = conn.cursor() cur.execute('SELECT * FROM exams') data = cur.fetchall() tableData = [[ 'id', 'Class Code', 'Type', 'Date', 'Days Left', 'Study Time' ]] for exam in data: tableData.append(exam) table = AsciiTable(tableData) print(table.table)
def show_table(self, itemClass): """ shows the itemType information in a table in ther terminal """ # Display title of table itemTitle = colored(itemClass.title, 'green') print("Item : " + itemTitle) # Fetch all the exams from the database conn = create_connection(itemClass.dbFile) cur = conn.cursor() cur.execute('SELECT * FROM ' + itemClass.tableName) data = cur.fetchall() print("Data Information ", data) # Copy the header of the item tableData = itemClass.headers.copy() for ele in data: tableData.append(ele) table = AsciiTable(tableData) print(table.table)
def add() : """ """ print("add") # * Get the information about the exam the user input info = input_exam() classCode = info["classCode"] type = info["type"] date = info["date"] daysLeft = info["daysLeft"] studyTime = info["studyTime"] # * Storing the data # Connect to a database -> if does not exist -> create conn = create_connection("exams_db.sqlite") # Execution create_table(conn, 'CREATE TABLE IF NOT EXISTS exams (id INTEGER PRIMARY KEY, classCode VARCHAR, type VARCHAR, date VARCHAR, daysLeft VARCHAR, studyTime INTEGER)') create_exam(conn,classCode, type, date, daysLeft, studyTime) # Saves the changes you made and quit conn.commit() conn.close()
def edit(self): """ edit an exam that was already entered """ print("edit") # Show the exams available self.mode_run("Show") # * Ask user fo the id id = self.id_input() # Confirmation question confirmation = [{ 'type': 'confirm', 'message': 'Are you sure you want to edit exam ?', 'name': 'confirm', 'default': False, }] confirmationAnswer = prompt(confirmation, style=custom_style_1) if confirmationAnswer['confirm'] == True: # Connect to a database -> if does not exist -> create conn = create_connection(self.database) # * Edit the exam with given id editQuestion = [ { 'type': 'list', 'name': 'item', 'message': 'Which item would you like to edit ?', 'choices': ['Class Code', 'Type', 'Date', 'Quit'] }, ] cur = conn.cursor() cur.execute("SELECT * FROM exams WHERE id=?", (id, )) data = cur.fetchall() # Saving the data for delivery id = data[0][0] classCode = data[0][1] type = data[0][2] date = data[0][3] daysLeft = data[0][4] studyTime = data[0][5] # Editing the specific data the user wants to edit quitFlag = False while quitFlag != True: editQuestionAnswer = prompt(editQuself.id - idestion, style=custom_style_2) if editQuestionAnswer['item'] == 'Quit': quitFlag = True # Saves the changes you made and quit conn.commit() conn.close() return if editQuestionAnswer['item'] == 'Type': type = self.type_input() elif editQuestionAnswer['item'] == 'Date': date = self.date_input() # Find out how many days left and if less than 5 -> make it bright red daysLeft = self.days_left(parse(date).date()) if daysLeft < 10: daysLeft = str(daysLeft) daysLeft = colored(daysLeft, 'white', 'on_red', attrs=['bold']) else: daysLeft = str(daysLeft) else: classCode = self.classCode_input() # Update update_exam(conn, id, classCode, type, date, daysLeft, studyTime) else: print("Operation Canceled.")