Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 2.03 KB

README.md

File metadata and controls

54 lines (42 loc) · 2.03 KB

Attendance-List

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.

What is needed

  1. Python3.7 (if not you will have to create a virtualenv using desired python version)
  2. Pipenv
  3. PostgreSQL + new clean database

How to run

  1. Clone this repository
  2. Navigate in terminal to directory containing Pipfile
  3. Run
gedit .env

and edit your database connection variables. If you're using other editor than Gedit then type name of this editor instead.

  1. Run
pipenv install

to install dependencies (Psycopg2 in this case).

  1. Run
pipenv shell

to enter virtual enviroment. At this point you should see (Attendance-List) prefix preceding your directory path.

  1. 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.

  1. 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.

Worth watching/checking:

Pycon talk from the creator of Pipenv: link

Pipenv tutorial by Corey Schafer: link

PostreSQL installation & configuration guide on Ubuntu: link

Psycopg2 docs: link