Logs Analysis Project for Udacity Full Stack Nanodegree.
This project uses psycopg2 to query a mock PostgreSQL database for a fictional news website. The questions answered by this program are:
- What are the most popular three articles of all time?
- Who are the most popular article authors of all time?
- On which days did more than 1% of requests lead to errors?
The database that this program queries contains three tables: articles, authors and log. The definitions of these tables is as follows:
author | integer | not null
title | text | not null
slug | text | not null
lead | text |
body | text |
time | timestamp with time zone | default now()
id | integer | not null default nextval('articles_id_seq'::regclass)
name | text | not null
bio | text |
id | integer | not null default nextval('authors_id_seq'::regclass)
path | text |
ip | inet |
method | text |
status | text |
time | timestamp with time zone | default now()
id | integer | not null default nextval('log_id_seq'::regclass)
This project uses a virtual machine (VM) to run a SQL database server.
- If you don't already have virtual box on your machine, you can download it here:
- Download and install Vagrant (if you do not already have it installed). This is the software that configures the VM and allows the host (your machine) to talk to the VM:
- https://www.vagrantup.com/downloads.html
- you should be able to run
$ vagrant --version
after installation to see the version that was installed.
- Clone this repository: https://github.com/udacity/fullstack-nanodegree-vm to a directory on your local machine and then cd into this directory.
- cd into the vagrant/ subdirectory
- Bring the VM up with the command
vagrant up
- Log into the VM with
vagrant ssh
- Download the news data from here:
- Unzip this file and move the newsdata.sql file into your vagrant directory
- cd into the vagrant directory and run
psql -d news -f newsdata.sql
- This will connect to the news database and populate the tables with the data contained in the sql file.
- Clone this repository to your local drive: https://github.com/jkolden/Logs-Analysis
- Copy the news.py file into the fullstack-nanodegree-vm/vagrant directory.
- Open a terminal window from the fullstack-nanodegree-vm/vagrant directory, or simply open a terminal window and cd into that directory.
- Run vagrant ssh at the prompt to log in to the VM.
$ vagrant ssh
- cd into the vagrant subdirectory
vagrant@vagrant:~$ cd /vagrant
- Run the news.py program
vagrant@vagrant:/vagrant$ python news.py
- The program's output will be displayed in the terminal window.