A reporting tool that prints out reports (in plain text) based on the data in the news database. This reporting tool is a Python program using the psycopg2 module to connect to the database.
News is a mock database for a news website. It contains tables with information about newspaper articles, authors as well as the web server log for the site. The log has a database row for each time a reader loaded a web page. Version of Python used: 3.6.1
Project files :
newsreport.py - Python program file that connects to the news database and executes the sql to print to results.
newsdata.txt - Copy of the result that the program printed out.
newsdata.sql - File used to create tables and populate them with data.
-
Install Python
-
Create the news database
This project makes use of Linux-based virtual machine (VM). This will give you the PostgreSQL database and support software needed for this project. Install the virtual machine. We're using tools called Vagrant and VirtualBox to install and manage the VM
Install VirtualBox
VirtualBox is the software that actually runs the virtual machine. You can download it from virtualbox.org. Install the platform package for your operating system.
Install Vagrant
Vagrant is the software that configures the VM and lets share files between your host computer and the VM's filesystem. Download it from vagrantup.com. Install the version for your operating system.
From your terminal, inside the vagrant subdirectory, run the command vagrant up
. This will cause Vagrant to download the Linux operating system and install it. This may take quite a while. Then log into it with vagrant ssh
.
- Download the news zip file and unzip the file. The file inside is called newsdata.sql. Put this file into the vagrant directory, which is shared with your virtual machine.
- To load the data, use the command
psql -d news -f newsdata.sql
. Running this command will connect to your installed database server and execute the SQL commands in the downloaded file, creating tables and populating them with data.
To Start the news logs analysis report application:
- Open the command line tool
- Inside the vagrant subdirectory(cd /vagrant), navigate to the directory containing the newsreport.py folder. Run the command
python3 newsreport.py
- The three project questions are printed along with the answer
The news logs data is provided by Udacity.