by Gene Ting-Chun Kao
The goal of this project is to write a internal reporting tool for a newspaper site to discover what kind of articles the site's reader like.
This python code connects to postgresql database and write the report as a output.txt file.
-
VirtualBox. (Tested with version 5.2.6 r120293 Qt5.6.3)
-
Vagrant. (Tested with 2.0.2)
-
Python3
- Clone my repo
git clone https://github.com/GeneKao/logs-analysis.git
- Move the directory folder
cd logs-analysis
- Install the Vagrant environment by running
vagrant up
. - Log in to the virtual machine
vagrant ssh
. - Download the database file here and extract to our project directory.
- Load the data to Vagrant VM
psql -d news -f newsdata.sql
. - Generate the report
python3 main.py
. - See the result
cat output.txt
.
- Go to database
psql -d news
. - List all the tables
\dt
. - Look at the specific table such as articles
\d articles
.
The python code follow PEP8 style, and Google Style Python Docstrings, and using object-oriented design for this report generating tool. A class called Reporter contains functions such as write_report and publish_reports. To use the Reporter class, you will need to use keyword "with" so the instance will automatically close the connection after it finishes its job. Questions and answers are written in the dictionaries so this can be flexible enough to be extended in the future.
Any suggestion please contact me.