All the assignments for the 9-week training for Python, Flask and SQL
- Clone that repo locally:
- Open the project in PyCharm
- Install Dependencies
- Navigate to the 'assignment-4-API-building' Directory
Before running the API, ensure you have the following installed:
- Python 3.x
- Flask
- MySQL Connector for Python
- Requests
You can install the required packages using pip. Create a requirements.txt
file with the following content:
Flask
mysql-connector-python
requests
Then run:
pip install -r requirements.txt
You need to edit the db_config.py
file to set up your database connection parameters. Create a file named db_config.py
and define the following variables:
USER = 'your_database_username'
PASSWORD = 'your_database_password'
HOST = 'localhost' # or your database host
DB_NAME = 'dramas' # the name of your database
Replace your_database_username
, your_database_password
, and other details with your actual database credentials.
- Start the Flask application: Navigate to the directory where your
app.py
file is located, then run the following command:
python app.py
This will start the Flask server, and you should see output indicating that the server is running, typically at http://127.0.0.1:5000/
.
- Testing the API: You can test the API using tools like Postman or directly through the command line using curl or by running the
main.py
script that provides a command-line interface to interact with the API.
Returns a greeting message.
Response Example:
{
"Greeting": "Hello, you are finally here!"
}
Returns all dramas in the database.
Response Example:
[
{
"Name": "The Bridal Mask",
"Year of release": "2012",
...
},
...
]
Searches for a drama by name.
Response Example:
{
"Name": "The Bridal Mask",
"Year of release": "2012",
...
}
Error Response (if not found):
{
"error": "😞 Drama not found! 🚫"
}
Adds a new drama.
Request Body Example:
{
"Name": "The Bridal Mask",
"Year of release": "2012",
...
}
Response Example:
{
"message": "🎉 Drama added successfully! 🎊✨",
"drama": {
...
}
}
Updates an existing drama's information.
Request Body Example:
{
"New content": "🎉 The information has been updated successfully",
"Rating": "9.5"
}
Response Example:
{
"Name": "The Bridal Mask",
"Year of release": "2012",
...
}
Deletes a drama by name.
Response Example:
{
"message": "🎉 'The Bridal Mask' has been deleted successfully. 🎊✨",
"deleted": {
...
}
}
Error Response (if not found):
{
"error": "'The Bridal Mask' not found."
}
You should now have a K-Dramas Management API set up and ready to use. Have fun!
- Make sure to customize the
db_config.py
and any other configuration files according to your setup. - Ensure your database schema matches the expected structure used in your queries.
- You can test the endpoints using tools like Postman or directly in your
main.py
.
Check out the demo video: Watch on YouTube
- Clone that repo locally and navigate to the 'assignment-3-fecthing-api' directory
- Open the project in PyCharm
- Install Dependencies
- Navigate to the root Directory
- Run the project locally:
python3 Pokemon.py
- Open in a Browser:
Once the server is running, open your web browser and navigate to the local link provided in the terminal (usually http://127.0.0.1:5000).
Flask is a micro web framework written in Python.
For more details, please go to: https://flask.palletsprojects.com/en/3.0.x/#
- Clone that repo locally and navigate to the 'assignment-2-sql-db' directory to check out the course schema.
Session 3--Clone a repo and connect remote and local repo:
If making a repository locally - start from:
- If cloning a repository,
git clone repository
, ensure you have the main (default branch) changes pulled, and then continue from step 3. - If you have a repository already connected/setup on GitHub, replace step 1 with checking out main (
git checkout origin main
) and pulling the changes (git pull
).
Steps:
git init
git checkout -b new_branch_name
<- to work on a branch (we did not cover this today though)- Make your changes, add files, edit code, etc.
- When you wish to save, add your files to the staging area (bank of things to be committed) using
git add .
(orgit add filename
) git commit -m "meaningful commit message"
git push
- If you don't have a branch set up on the remote yet (we didn't cover branches today), it will tell you what code to run (e.g.,
git push --set-upstream origin branch_name
) - Repeat from step 3 until you're complete (you'll look at when to move onto a new branch, and what they are in more detail, later)
Session 4--Create and switch branches, push local changes and create pull requests:
- Make a repo on GitHub (including the readme file option and make sure it's private).
- Clone that repo locally:
- Make a branch:
git switch name-of-branch
- Make the changes locally:
git add . git commit -m "description of the changes you made!" git push