Data Representation Project, GMIT 2020-2021
Author: Andrzej Kocielski
Github: andkoc001
Email: G00376291@gmit.ie
This is my assignment project to Data Representation module, Galway-Mayo Institute of Technology, 2020.
This GitHub repository documents my research, project progress (git version control) and findings of the assignment project - a Web Application deployment.
In this README.md file I have incorporated the research and described the project progress. It is illustrated with the applied concepts and methods together with relevant code snippets.
The project is based predominantly and heavily on the lecture materials. The reference to the lecture materials is not specifically provided. General resources are listed at the bottom of this README.md file. More specific references are provided the text body when applicable. The project source code and resources are also available on this GitHub repository.
The objective of the is to develop a web service to access, display, modify etc. data from an API using Flask back-end framework and other tools commonly used in the industry, such as Python programing language, Flask, Git, etc. as required.
The goal of the project is to produce a web app that will do the following:
- Consuming a RESTful API, either in Python (server) or javascript (client)
- Running the server
- CRUD operations on data (create, read, update, delete)
- Web frontend to display data and interact with server.
The detailed project instruction can be found in the [file]https://github.com/andkoc001/Data_Rep_Project.git/blob/main/Project%20Description.pdf
The SQL database used for this project consists of one table "equipment". It schema looks as per below image:
The project is delivered so that it can be accessed in two ways:
- By setting up a local server (see below instructions).
- Depoloyed on the PythonAnywhere server. It is accessible at the following address: andkoc001.pythonanywhere.com.
Note: The web app requires credential authentication. For the purpose of this assignment use >> gmit << for both user name and password.
Please follow the below steps to set up a local host server.
Go to https://github.com/andkoc001/Data_Rep_Project.git website and, click on 'Code' button and then 'Download ZIP'. Unzip the downloaded file on your hard drive.
Ensure all the required modules are installed. In the folder, where the repository has been unzipped, start the terminal (Linux systems, on Windows use the counterpart). Install the required modules, specified in requirements.txt, typing:
pip3 install -r requirements.txt
In the project folder run MySQL (more about MySQL):
mysql -uusername -ppass
where 'username' is your mysql username and 'pass' is your mysql password.
While MySQL is running, create a new database 'datarepresentation' and switch to this database
CREATE DATABASE datarepresentation;
USE datarepresentation;
Create a new schema for the table 'equipment':
CREATE TABLE equipment (
id INT PRIMARY KEY AUTO_INCREMENT,
category ENUM('Tier 1', 'Tier 2', 'Auxiliary', 'Spare') DEFAULT 'Tier 1',
name VARCHAR(50),
supplier VARCHAR(50),
price_eur FLOAT(10, 2)
);
Create a new file called 'config.py'. Paste in the following:
mysql = {
'host': 'localhost',
'user': 'username',
'password': 'pass',
'database': 'datarepresentation'
}
where 'username' should be replaced with your username, and 'pass' - with your password.
On Linux systems, type:
export FLASK_APP=app.py
python3 -m flask run
On Windows systems, type:
set FLASK_APP=app.py
python -m flask run
Keep the virtual environment running. Press ctrl+c to terminate the server.
On a new terminal (separate to the one keeping the server running) test the connection by checking the http responses with the Curl, for example:
curl -i http://localhost:5000/
In your Internet browser, access the following address: http://localhost:5000/.
General, high-level, reference sources are listed below. References to specific problems are included in the Notebook.
- Project details project brief.
- Python 3 Documentation. [online] Available at: https://docs.python.org/3/ [Accessed November 2020].
- Python Virtual Environment. [online] Available at: https://docs.python-guide.org/dev/virtualenvs/ [Accessed November 2020].
- Flask User Guide - [online] Available at: https://flask.palletsprojects.com/en/1.1.x/#user-s-guide [Accessed December 2020].
- Julian Nash - Learning Flask - [online] Available at: https://pythonise.com/series/learning-flask [Accessed December 2020].
- A beginner's guide to building a simple database-backed Flask website on PythonAnywhere - [online] Available at: https://blog.pythonanywhere.com/121/ [Accessed December 2020].
- Caleb Curry - REST API Crash Course.[online] Available at: https://docs.google.com/document/d/1v0l4TC2ZyFYyk6Y0ggFw86li2F6cwr5GLuTUyrzSpT4/edit# [Accessed December 2020].
- REST API Crash Course [online] Available at: https://youtu.be/qbLc5a9jdXo and https://docs.google.com/document/d/1v0l4TC2ZyFYyk6Y0ggFw86li2F6cwr5GLuTUyrzSpT4/edit [Accessed December 2020].
- MySQL documenation. [online] Available at: [https://docs.python.org/3/](https://dev.mysql.com/doc/) [Accessed December 2020].
- How to manage MySQL databases, users, and tables from the command line [online] Available at: https://www.a2hosting.com/kb/developer-corner/mysql/managing-mysql-databases-and-users-from-the-command-line [Accessed December 2020]
Andrzej Kocielski, 2020