GithubHelp home page GithubHelp logo

ngnnah / cs50-pset9-finance Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 43.0 18 KB

Implement a website via which users can “buy” and “sell” stocks (with real-time share prices, user account database, cookie session)

Home Page: https://cs50.harvard.edu/x/2021/psets/9/finance/

Python 49.29% CSS 3.07% HTML 47.64%
iex-api flask flask-application flask-sqlalchemy bootstrap5 sqlite sql sqlite3 sqlite-database database-schema

cs50-pset9-finance's Introduction

cs50-pset9-finance

Another fun and exciting project: I built a full-stack web app with Bootstrap UI, Flask back-end, and SQLite3 database.

DEMO

Transaction history

Orders table

USAGE:

First, you will need to get an API key from IEX (free account registration), which lets you download stock quotes via their API (application programming interface) using URLs like https://cloud.iexapis.com/stable/stock/nflx/quote?token=API_KEY

With the API, run the following within a CS50 IDE's terminal: $ export API_KEY=value (value is your acquired personal API KEY)

Start Flask’s built-in web server: $ flask run

In this pset, I have implemented:

  • App Features: register, quote, buy, index, sell, history
  • most of html templates (lots of Jinja dynamic content generation) and their UIs
  • application.py (lots of routing, logics, and Sqlite3 QUERIES)
  • Design an orders table to keep track of all stock transactions by all users. It is stored in finance.db

Some of my own notes, while watching Week9 lecture video

Flask app file structure: • application.py • requirements.txt • static/ • templates/

MODEL-VIEW-CONTROLLER (MVC) design pattern - model=SQL(..) the database, - view=what user sees, templates,

  • controller=application.py, the logics that connect M-V, plus routing

  • jinja: Used in HTML templates: {{ var }} , {% block x %} {% endblock %}.

Make use of TEMPLATES: factor out a COMMON layout.html

  • {% block body %} {% endblock %}
  • in index.html, about.html, etc.: {% extends "layout.html" %} {% block body %} the content {% endblock %}

SENDING emails with Flask: image

Privacy concern: In dev environment: store personal info in virtual environment variables (export username=..., and later retrieve via os.getenv("USERNAME"))

It's easy to implement Cookie Session in Flask

  • Session: basically, servers plants cookie (i.e. a saved state, a file, a large number) on your device, to help them remember your identity.
  • How it works? BROWSER (if have a cookie) sends cookie along with GET requests, and SERVER: validates, then skip login during same sesson, server personal data, etc.
  • ENTER Incognito mode: not employing cookies.

Callback: a function that will eventually be called, when it has an answer for you.

An AJAX call: sends additional HTTP request to server (for chat messages, autocomplete, etc.). So WHEN the response is ready, the callback function would receive the response as its argument.

NOTE for pset9 Finance:

Primary key vs Unique key:

  • A primary key is a column of table which uniquely identifies each tuple (row) in that table.
  • Primary key will not accept NULL values whereas Unique key can accept one NULL value. (a unique column might have rows with NULL values)
  • A table can have only primary key (column), and multiple unique keys (columns).

cs50-pset9-finance's People

Contributors

ngnnah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.