Database retrieval application for a hypothetical streaming service.
- Clone the repository.
- Make sure you downloaded Python.
- Enable/Download the Python extension.
- Create a virtual environment by running
python -m venv venv
(if this doesn't work, try withpython3
orpy
instead). If VSCode registers your virtual environment correctly, it will prompt you to 'use this virtual environment' and you are all set. - If the prompt does not pop up, hit CTRL+Shift+P to open the VSCode Palette. Search for 'Python: Select Interpreter'. Choose 'Enter Interpreter Path'. Go to this project's directory, go to the venv directory, choose python.exe.
- Open a new terminal, and you should see a
(venv)
in green before your directory path.
- Get the creds.json file from Google Drive.
- Get the env file from Google Drive.
- Add the creds.json file to this project directory.
- Run
$env:GOOGLE_APPLICATION_CREDENTIALS='creds.json'
so that it knows where to pull the Google credentials for Google Cloud.- (For Mac users) Run
export VAR_NAME=value
instead.$env
only works on Windows.
- (For Mac users) Run
- Run all commands from env file.
- Get access from Kay to the Google Cloud terminal so you can view the database from your Google Cloud console.
- Run
pip install -r requirements.txt
to get all dependencies.
- If you've done everything until now with no errors, you should be able to run the server.
- On the terminal, run
python manage.py runserver
. It should have a link for you (localhost). - Change the path to 'http:localhost:/' and you should see rows of medias.
- Click on the add, search or analyse button, and it should bring you to those respective pages.
- The connection between Cloud MySQL and the project is in
welcome/__init__.py
. - The connection object (the engine) is in
welcome/db.py
. This object will be used for all future query requests from the database. template
folders are for html files.static
folders are for css files.- Currently everything is in welcome directory. We might want to separate ourselves into 4 smaller directories, or we can all do it in one directory.
- There are a couple of mini examples I set up (which we will delete them once we get the hang of it), which retrieves all media, and inserts a constant media object. They are in the welcome directory.
-
urls.py
: Holds all the major paths. Root starts with/
. -
welcome/views.py
: "view" functions of each url. Determines the response for each request from the user. Currently holds function to communicate with the database. We might want to separate the db query logic out into its own file, and this file only holds logic for 'GET', 'POST', 'DELETE' requests. -
welcome/urls.py
: Holds all the sub-paths with the root path 'welcome'. -
welcome/models.py
: Holds all the models (the "table schema" to make quering easier). We should have a Model blueprint for every table we have. -
welcome/db.py
: The engine class object. We will use this object for all query requests. -
welcome/__init__.py
: Holds the connection between the project and the Cloud MySQL. -
welcome/templates
: Holds all HTML files. These HTML files are referenced inview.py
in therender()
function. (Each major component should have their own sub-directory, like how welcome has its own.) -
welcome/static
: Holds all CSS files. These CSS files are referenced in HTML files. (Each major component should have their own sub-directory, like how welcome has its own.)
Our main package used is mysqlalchemy
. We can use raw SQL, ORM, prepared statements with this package. Not sure how stored procedures work yet.
Reference: https://docs.sqlalchemy.org/en/14/orm/queryguide.html
We will use Bootstrap for styling because all we need is just a link. If Samara has any other ideas then we can use it. We can also add CSS files for customized styling. Reference: https://getbootstrap.com/docs/4.5/components/alerts/
-
Github branches -- To manage future merge conflicts and avoid crashing the main code, we should all work on our own branch. Do a
git pull origin main
before you code every time you work on the project to avoid any future merge conflicts. You can run thegit add
,git commit
andgit push
as usual in your branch, and after that, on the Github website, open a pull request and merge it. This way helps keeping track of code history. -
Python-self generated files -- Often times when we run Python, it will generate random files in our directory that keeps our code working but we have no idea what they does and 90% of the time they are machine-dependent. We don't want those files to create chaos, so before running
git add
, add those files (or directory) to the.gitignore
file so that Git will not track them. (a good example is thevenv
folder) -
Packages -- If you are using new packages, add them to the
requirements.txt
file so that others who pulled your code, can just runpip install -r requirements.txt
and get them.