WEBVTT 1 00:00:00.351 --> 00:00:01.184 Hi there, 2 00:00:01.184 --> 00:00:04.739 and welcome to your second milestone project. 3 00:00:04.739 --> 00:00:06.830 This project is going to be pretty cool. 4 00:00:06.830 --> 00:00:09.268 It's going to allow us to store the books 5 00:00:09.268 --> 00:00:11.141 we're reading and then go back 6 00:00:11.141 --> 00:00:12.397 and mark them as read. 7 00:00:12.397 --> 00:00:13.529 So, for example, we can keep track 8 00:00:13.529 --> 00:00:15.665 of everything we've read so far 9 00:00:15.665 --> 00:00:17.464 and what we want to read in the future. 10 00:00:17.464 --> 00:00:19.232 The most exciting part about this project though, 11 00:00:19.232 --> 00:00:21.724 is the way we're going to bait it. 12 00:00:21.724 --> 00:00:26.172 We're going to start by using an in memory database, 13 00:00:26.172 --> 00:00:28.976 which is just a Python list. 14 00:00:28.976 --> 00:00:31.000 Then we're going to extend it, 15 00:00:31.000 --> 00:00:32.726 so that instead of saving things in a list, 16 00:00:32.726 --> 00:00:35.167 it saves them in a file. 17 00:00:35.167 --> 00:00:37.579 And afterwards, we're going to extend it further still, 18 00:00:37.579 --> 00:00:40.912 like saving things to a sequel database. 19 00:00:42.274 --> 00:00:44.712 Building the project in these three distinct steps 20 00:00:44.712 --> 00:00:46.278 is going to help us really understand 21 00:00:46.278 --> 00:00:47.796 what's going on behind the scenes. 22 00:00:47.796 --> 00:00:50.437 So please bear with me as we go through this. 23 00:00:50.437 --> 00:00:52.138 We're going to have some coding sessions, 24 00:00:52.138 --> 00:00:54.570 like the one you see in your video right now 25 00:00:54.570 --> 00:00:56.565 interspersed with some slightly more 26 00:00:56.565 --> 00:00:59.249 theoretical sessions where we'll talk about 27 00:00:59.249 --> 00:01:00.822 databases and how they work, 28 00:01:00.822 --> 00:01:03.067 and also how to use them. 29 00:01:03.067 --> 00:01:05.493 If you don't know what a database is, don't worry. 30 00:01:05.493 --> 00:01:07.190 Through this section, you're going 31 00:01:07.190 --> 00:01:08.839 to understand exactly what goes on 32 00:01:08.839 --> 00:01:12.672 inside a database and why we want to use them. 33 00:01:13.540 --> 00:01:14.674 Your milestone project, though, 34 00:01:14.674 --> 00:01:16.924 is going to be a book list. 35 00:01:19.008 --> 00:01:20.517 So in the next lecture, 36 00:01:20.517 --> 00:01:22.687 you're going to have a brief explaining exactly 37 00:01:22.687 --> 00:01:25.926 what I want you to do for this project. 38 00:01:25.926 --> 00:01:27.971 But I also wanted to give you some 39 00:01:27.971 --> 00:01:29.979 brief instructions in this video, 40 00:01:29.979 --> 00:01:33.283 just to help you along your way. 41 00:01:33.283 --> 00:01:35.999 Our project is going to have two files. 42 00:01:35.999 --> 00:01:38.582 It's going to have an app file, 43 00:01:39.447 --> 00:01:41.386 and it's also going to have a package, 44 00:01:41.386 --> 00:01:43.719 which is going to be called utils. 45 00:01:43.719 --> 00:01:45.052 Not ITOs, utils. 46 00:01:46.332 --> 00:01:47.853 And inside utils, we're going to have another 47 00:01:47.853 --> 00:01:51.436 file which we're going to call database.py. 48 00:01:52.729 --> 00:01:54.691 This database.py is going to be 49 00:01:54.691 --> 00:01:57.774 concerned with storing and retrieving 50 00:01:59.020 --> 00:02:00.520 books from a list. 51 00:02:02.476 --> 00:02:03.590 Okay, so it's not really going to be 52 00:02:03.590 --> 00:02:05.476 a sequel database just now it's going to be 53 00:02:05.476 --> 00:02:07.387 an in memory database. 54 00:02:07.387 --> 00:02:09.877 And we're going to have a books list, 55 00:02:09.877 --> 00:02:13.372 which is going to be an empty list to begin with. 56 00:02:13.372 --> 00:02:15.122 And we're also going to have some functions here 57 00:02:15.122 --> 00:02:16.918 to add a new book to our list, 58 00:02:16.918 --> 00:02:19.088 to retrieve the books from our list, 59 00:02:19.088 --> 00:02:20.069 and so forth. 60 00:02:20.069 --> 00:02:21.600 The brief is going to have a lot more information 61 00:02:21.600 --> 00:02:23.606 on exactly the layout of this file 62 00:02:23.606 --> 00:02:26.751 and how it's going to be used. 63 00:02:26.751 --> 00:02:30.351 In app.py, we're going to have our user menu. 64 00:02:30.351 --> 00:02:31.308 Of course, this is going to be 65 00:02:31.308 --> 00:02:32.894 a text based application, 66 00:02:32.894 --> 00:02:35.732 we haven't looked at making graphical interfaces just yet. 67 00:02:35.732 --> 00:02:39.227 So we're going to do everything via text. 68 00:02:39.227 --> 00:02:42.727 For that, we are going to have two things. 69 00:02:44.144 --> 00:02:46.800 First one is we are going to import database 70 00:02:46.800 --> 00:02:49.116 in order that we can deal with saving things 71 00:02:49.116 --> 00:02:51.487 to our books list and so forth. 72 00:02:51.487 --> 00:02:54.795 And we're also going to have a user choice. 73 00:02:54.795 --> 00:02:56.467 And this is going to be a multi-line string, 74 00:02:56.467 --> 00:02:58.587 which is going to describe to the user 75 00:02:58.587 --> 00:03:00.385 what they can do. 76 00:03:00.385 --> 00:03:03.166 So I am going to just copy it from my notes here. 77 00:03:03.166 --> 00:03:05.666 And like so, your choice here. 78 00:03:09.912 --> 00:03:10.899 So the user choice is what we're 79 00:03:10.899 --> 00:03:12.350 going to print out for the user 80 00:03:12.350 --> 00:03:14.670 to know what sort of things they can type. 81 00:03:14.670 --> 00:03:15.503 And that's going to be 82 00:03:15.503 --> 00:03:18.544 'a' to add a new book, 'l' to list all books, 83 00:03:18.544 --> 00:03:22.275 'r' to mark a book as read, 'd' to delete a book, 84 00:03:22.275 --> 00:03:24.047 and 'q' to quit. 85 00:03:24.047 --> 00:03:25.400 We've already created a menu 86 00:03:25.400 --> 00:03:26.918 for our last milestone project, 87 00:03:26.918 --> 00:03:28.998 so you know how this goes. 88 00:03:28.998 --> 00:03:31.472 We're going to have a menu here. 89 00:03:31.472 --> 00:03:33.231 And then we are going to sort of 90 00:03:33.231 --> 00:03:34.814 get the user input. 91 00:03:36.580 --> 00:03:38.929 And then we're going to have a user input 92 00:03:38.929 --> 00:03:40.853 is not 'q', y loop. 93 00:03:40.853 --> 00:03:44.916 And here we're going to ask the user stuff. 94 00:03:44.916 --> 00:03:46.115 Sorry, not going to ask the user stuff, 95 00:03:46.115 --> 00:03:46.948 but we're going to actually 96 00:03:46.948 --> 00:03:48.096 deal with the user's inputs. 97 00:03:48.096 --> 00:03:49.849 So if they enter 'a', we're going to call 98 00:03:49.849 --> 00:03:51.868 a function that adds a book. 99 00:03:51.868 --> 00:03:52.983 If they enter 'l', 100 00:03:52.983 --> 00:03:55.464 we're going to call a function that lists all books, 101 00:03:55.464 --> 00:03:56.566 and so forth. 102 00:03:56.566 --> 00:03:59.626 So down here, you'll probably have 103 00:03:59.626 --> 00:04:03.557 something that looks like prompt_add_book. 104 00:04:03.557 --> 00:04:05.140 And def list_books. 105 00:04:06.206 --> 00:04:08.289 And def prompt_read_book. 106 00:04:09.810 --> 00:04:12.060 And def prompt_delete_book. 107 00:04:13.416 --> 00:04:14.249 Like so. 108 00:04:14.249 --> 00:04:15.778 So each of these functions should do something. 109 00:04:15.778 --> 00:04:19.102 This one's probably going to ask for 110 00:04:19.102 --> 00:04:20.852 book name and author. 111 00:04:22.744 --> 00:04:26.518 This one's gonna show all the books in our list. 112 00:04:26.518 --> 00:04:29.313 This one's probably ask for book name 113 00:04:29.313 --> 00:04:32.313 and change it to 'read' in our list. 114 00:04:33.336 --> 00:04:37.466 And this one's going to remove book from list. 115 00:04:37.466 --> 00:04:40.554 Ask for book name and remove book from list. 116 00:04:40.554 --> 00:04:44.052 So these are probably going to be your functions. 117 00:04:44.052 --> 00:04:45.691 In the prompt add book, 118 00:04:45.691 --> 00:04:48.302 you're going to be interacting with the database file 119 00:04:48.302 --> 00:04:51.135 to add a new book to our database. 120 00:04:52.332 --> 00:04:53.836 What I'm thinking is a database file 121 00:04:53.836 --> 00:04:56.191 will have something like add_book. 122 00:04:56.191 --> 00:04:59.292 And that's going to take the book name and author. 123 00:04:59.292 --> 00:05:00.992 And there's probably going to do something 124 00:05:00.992 --> 00:05:03.492 like books_append name is name 125 00:05:06.113 --> 00:05:09.446 and author is author, and read is false. 126 00:05:10.299 --> 00:05:13.869 Because it's not been read at the start. 127 00:05:13.869 --> 00:05:14.702 Okay. 128 00:05:15.546 --> 00:05:17.107 Now you'll have to create other functions here 129 00:05:17.107 --> 00:05:18.994 to do something like retrieve all 130 00:05:18.994 --> 00:05:20.968 the books from our list. 131 00:05:20.968 --> 00:05:22.202 You're going to have to add something 132 00:05:22.202 --> 00:05:25.675 to modify a book so it is now read, 133 00:05:25.675 --> 00:05:27.888 and of course, delete a book. 134 00:05:27.888 --> 00:05:28.919 And also you'll have to implement 135 00:05:28.919 --> 00:05:32.169 this menu here and all these functions. 136 00:05:33.019 --> 00:05:34.708 Read the brief in the very next lecture. 137 00:05:34.708 --> 00:05:35.849 It's got a bunch more information 138 00:05:35.849 --> 00:05:39.544 on exactly the motivation behind this project 139 00:05:39.544 --> 00:05:42.354 and also some hints and tips to help you 140 00:05:42.354 --> 00:05:43.428 along your way. 141 00:05:43.428 --> 00:05:46.079 But please do attempt this on your own 142 00:05:46.079 --> 00:05:49.123 before moving onto the next programming video 143 00:05:49.123 --> 00:05:51.119 where we'll be implementing this. 144 00:05:51.119 --> 00:05:52.702 I'll see you soon.