Also notice how login “remembers” that a user is logged in by storing his or her user_id, an INTEGER, in session. And notice how it uses check_password_hash to compare hashes of users’ passwords. Notice how it uses db.execute (from CS50’s library) to query finance.db. Read through the implementation of login first. Thereafter are a whole bunch of routes, only two of which are fully implemented: login and logout. The file then configures CS50’s SQL module to use finance.db. It then further configures Flask to store sessions on the local filesystem (i.e., disk) as opposed to storing them inside of (digitally signed) cookies, which is Flask’s default. Notice next how it configures Jinja with a custom “filter,” usd, a function (defined in helpers.py) that will make it easier to format values as US dollars (USD). More on those soon.Īfter configuring Flask, notice how this file disables caching of responses (provided you’re in debugging mode, which you are by default in your code50 codespace), lest you make a change to some file but your browser not notice. Atop the file are a bunch of imports, among them CS50’s SQL module and a few helper functions. You should see information about the database itself, as well as a table, users, just like you saw in the sqlite3 prompt with. Click on finance.db in your codespace’s file browser, then click the link shown underneath the text “Please visit the following link to authorize GitHub Preview”. But if you run SELECT * FROM users, there aren’t (yet!) any users (i.e., rows) therein to browse.Īnother way to view finance.db is with a program called phpLiteAdmin. Notice how, by default, new users will receive $10,000 in cash. Take a look at its structure (i.e., schema). schema in the SQLite prompt, notice how finance.db comes with a table called users. Within finance/, run sqlite3 finance.db to open finance.db with sqlite3. You won’t be able to log in or register, though, just yet! Visit the URL outputted by flask to see the distribution code in action. You should find that your terminal window’s prompt resembles the below: Log into v, click on your terminal window, and execute cd by itself. Let’s turn our attention now to getting this problem’s distribution code! Getting Started We’re going to be doing something very similar, with Yahoo Finance. Notice how, between the curly braces, there’s a comma-separated list of key-value pairs, with a colon separating each key from its value. That link won’t actually return any data because IEX requires you to use an API key, but if it did, you’d see a response in JSON (JavaScript Object Notation) format like this: Notice how Netflix’s symbol (NFLX) is embedded in this URL that’s how IEX knows whose data to return. Indeed, there are tools (one is known as IEX) that let you download stock quotes via their API (application programming interface) using URLs like. Not only will this tool allow you to check real stocks’ actual prices and portfolios’ values, it will also let you buy (okay, “buy”) and sell (okay, “sell”) stocks by querying for stocks’ prices. You’re about to implement C$50 Finance, a web app via which you can manage portfolios of stocks. If you’re not quite sure what it means to buy and sell stocks (i.e., shares of a company), head here for a tutorial. Implement a website via which users can “buy” and “sell” stocks, a la the below. GitHub Instagram LinkedIn Reddit Threads Twitter This is CS50 CS50’s Introduction to Computer Scienceĭavid J.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |