In This project we are dealing with the database of a newspaper site that contains three main tables: Authors, Articles and log. we have been asked to build an internal reporting tool to now what's the best articles and authors based on the pages visit that are stated in the log table. To do this task, we (me and other students) have been asked to use python programming language and run the program in the terminal.
For the database part, this project use postegre SQL database in connection in python code file.
To start working on the project you will need to have the following folder which include the data you will work on (newsdata.sql) which we will use mainly for this project.
- you can download the zip folder here
The python file (project_log_roaa.py) is the main file in this project. From it we can deal with the database. It has the connection code to the database and include the DB queries that fetch the information needed to answere these three questions:
-
What are the most popular three article of all time?
-
What are the most popular Authors of all time?
-
On which days did more than 1% requests lead to errors?
so basically the python file process three different queries.
you will need to download the following:
-
Git bash ( https://git-scm.com/downloads) for windows, for Mac or Linux systems, you can use the built-in Terminal.
-
Pyhton 3: (https://www.python.org)
-
Psycopg2 v2.7.5: (http://initd.org/psycopg/download/)
-
PostgreSQL v9.5.14: (https://www.postgresql.org/download/)
-
Vagrant: (https://www.vagrantup.com/downloads.html)
-
Virtual Machine v5.1.38: (https://www.virtualbox.org/wiki/Downloads)
to use and test the project to see the outputs follow these instructions:
-
Open the Git bash termninal.
-
type command: cd [your folder name]
Your folder should include the vagrant folder(that includes vagrant VM) inorder to work on vagrant Commands
-
Now go to vagrant folder: cd vagrant
-
Run command: vagrant up
-
Then run: vagrant ssh
-
Go again to vagrant folder: cd /vagrant
-
run the python file project with the following command: python3 project_log_roaa.py
Please note that the python file should be in the same folder with vagrant vm folder and newsdata.sql
The output should be as following:
Most popular articles:
- Candidate is jerk, alleges rival - 338647 Views
- Bears love berries, alleges bear - 253801 Views
- Bad things gone, say good people - 170098 Views
Most popular authors:
- Ursula La Multa - 507594 views
- Rudolf von Treppenwitz - 423457 views
- Anonymous Contributor - 170098 views
- Markoff Chaney - 84557 views
Days with more than 1% errors:
- 2016-07-17 -- 2.26 % errors
1- First load the data from the sql file:
psql -d news -f newsdata.sql
2- Then connect to the database:
psql -d news
3- To view all DB tables type:
\dt
4- To see table details type:
\d log
log is a table name in the news database
- To exist the postegreSQL database: ctrl + C
- To exist Vagrant : ctrl + D
The code could be reused with different SQL database and different quires to fetch information from database.
This code belong to the author of this github profile. for any inquires please email: roaak2009@gmail.com