This is an internal reporting tool that produces answers by printing them out in the plain text in the Terminal. The tool produces answers to the following three questions based on the data in the database:
- What are the most popular three articles of all time?
- Who are the most popular articles authors of all time?
- On which days did more than 1% of requests lead to errors?
Writing the program with tool is a Python language program that uses the psycopg2 module to connect to the database.
Python For Writing program
PostgreSQL Download For Database
VirtualBox
Vagrant
Git
VM configuration file by Udacity from here or clone the repository from [here] (https://github.com/udacity/fullstack-nanodegree-vm)
Download Project Database from newsdata
can use any editor would do you like
visual Studio Code
sublime Text
Atom
Brackets
Python : https://docs.python.org/3/tutorial/index.html
Psycopg – PostgreSQL database adapter for Python : http://initd.org/psycopg/docs/index.html
PostgreSQL: https://www.postgresql.org/docs/9.4/index.html
This project makes use of Udacity's Linux-based virtual machine (VM) configuration which includes all of the necessary software to run the application.
- Download Vagrant and install.
- Download Virtual Box and install.
- Clone this repository to a directory of your choice.
- Download the newsdata.sql (extract from newsdata.zip (not provided here though)) and newsdata.py files from the respository and move them to your vagrant directory within your VM.
vagrant up
to start up the VM.vagrant ssh
to log into the VM.cd /vagrant
to change to your vagrant directory.psql -d news -f newsdata.sql
to load the data and create the tables.- Create view tables using the following command
CREATE VIEW total_view AS SELECT date(time), COUNT(*) AS totview
FROM log
GROUP BY date(time)
ORDER BY totview;
CREATE VIEW total_errors AS SELECT date(time), COUNT(*) AS errview
FROM log WHERE status= '404 NOT FOUND'
GROUP BY date(time)
ORDER BY errview;
CREATE VIEW percentage_errors AS
SELECT total_view.date,
round((total_errors.errview*100.0/total_view.totview), 3)AS percentage
FROM total_view, total_errors
WHERE total_view.date = total_errors.date
ORDER BY total_view.date;
python3 main.py
to run the reporting tool.
Python code quality
Your code should be written with good Python style. The PEP8 style guide is an excellent standard to follow. You can do a quick check using the pep8 command-line tool.
For more information on writing good READMEs, From udacity see this course.
If your command prompt does not start with vagrant after typing vagrant ssh
then please try the winpty vagrant ssh
on your Windows system.