00:00:00,970 --> 00:00:03,520 SPEAKER 1: This is see as CS50 Finance, where we'll make a website that allows users to sign up, register, log in, and buy and sell stocks or shares that they're interested in. Well, first, there's going to be a lot of distribution code for us to read over. There are Python files, HTML files, and even one database file, .db. And we have to understand how all of those interact with one another and the functions that we've provided that will make this problem a lot easier to handle. Then, once we read through all of that, we'll implement register, where users can sign up for the website. Then, we'll implement quote, which allows users to look up the price for a stock. Buy allows them to buy a certain number of shares of that stock. Then we'll edit the landing page and index, such that logged in users can see their transaction history as well as some other information about the cash that they have on hand and the total value of their holdings. We'll of course allow them to sell any shares that they have and view the history of those transactions. Finally, you'll have the freedom to implement an additional feature of your choosing. Now, this may seem like a lot of to-dos. And I'm also going to add some subtasks under each category. So it might be a little overwhelming, but as always, we're going to take this bit by bit and break it down into manageable bites. First, let's open application.py. You'll notice at the very top, we have a lot of dependencies. We import a lot of packages and modules. This will allow us easier functionality as we progress through this problem. Feel free to check out the documentation for all of these dependencies. Then we ensure that responses aren't cached. This means that whenever we make a request from the server, it actually fetches from the server as opposed to going into the cache. So we get fresh data every time. Then we configure the Flask session and configure the CS50 library to use the SQLite database. Then you'll notice that we have login required before every definition of these pages. That means that the user must be logged in order to access the given route. More on login required later on. As we continue through application.py, we'll notice that login and logout are both implemented for us. So these are going to be important to understand how they work but also to use as a framework to understand how we might implement the other routes. Also notice how we call the apology function and the database execute function. Some other things to take note of, whenever we have a form submission via post, we can retrieve it as follows. In our HTML template within the templates folder, if we have our HTML and we've specify the name of our input box, then within Python, we can then request that via request.form.get and then specify the name of that input in order to retrieve the variable that was submitted from the form. Note that the execute function for the SQL database always will return an array. So that means that even though I only selected one specific cash value for one specific user, in order to access that value, I'll have to access the very first row of the array rows and then go to the index of cash in order to get that value. Feel free to take some time and read through application.py so you really understand how it's working. For now, I'm going to move on to helpers.py, where we'll see the implementation for apology and login required. We'll also see the lockup function, which is going to be useful. Lookup allows us to take a stock symbol and then returns the name, price, and symbol of that stock encapsulated within a dict. It does this using Yahoo Finance, which allows us to fetch stock information via a URL. Then we have usd, which nicely formats the prices for us. Now we can move on to the templates directory. There are only three files in here, apology, layout, and login, all HTML files. So take a look at these and figure out how they interact with their respective routes with an application.py. And surely, you'll be adding additional templates as you progress through this problem. Finally, we have the requirements.txt and then the CCS style sheet which you can feel free to edit as you see fit. Once you're comfy with the distribution code, and I mean really comfy, then we can start implementing register.