This is a simple terminal-based app for checking the attendance. The project was created for Pylight: Python-oriented meetup for begginers. The main goal is to show how to establish a connection with PostgreSQL database using Psycopg2.
- Python3.7 (if not you will have to create a virtualenv using desired python version)
- Pipenv
- PostgreSQL + new clean database
- Clone this repository
- Navigate in terminal to directory containing Pipfile
- Run
gedit .env
and edit your database connection variables. If you're using other editor than Gedit then type name of this editor instead.
- Run
pipenv install
to install dependencies (Psycopg2 in this case).
- Run
pipenv shell
to enter virtual enviroment. At this point you should see (Attendance-List) prefix preceding your directory path.
- Run
python logic.py
to run the app. You should see a welcome message and menu. Type 'd' to create a required database structure. This button is also used for resetting your database. Keep in mind that it will drop existing table and create a new one.
- Keep exploring the source code. On branch 'with-decorator' you will find different implementation od the database connection using decorator. This implementation creates a new connection, executes a query and closes the connection every time you run the desired function. There is also a 'bad-example' which contains a function that uses simple string interpolation for passing arguments to SQL query. This is an anti-pattern and makes your app vulnerable to SQL injection.
Pycon talk from the creator of Pipenv: link
Pipenv tutorial by Corey Schafer: link
PostreSQL installation & configuration guide on Ubuntu: link
Psycopg2 docs: link