The Daily Bugle is a news site that has, as the name implies it, daily updates on major news along with the weather and a (hopefully) funny comic strip. The site uses each user's IP address (after given permission, of course) to find the weather data of their location using the IP API and Darksky API. The Ipify API is used to procure the client's IP address. The comics and news are based on the xkcd API and the NewYorkTimes API, respectively. Every day, there will be a new interesting article and a different comic strip!
The Daily Bugle makes use of 5 RESTful APIs. Each API, along with an explanation and link, are listed below.
- DarkSky API
The DarkSky API provides extensive information about a location's weather, along with a daily and weekly summary. We have used this API to display the client's local weather. An API key is required to use this REST API, see below to see how to get one.
- New York Times API
The New York Times API provides detailed news and headlines that, more often than not, have huge impacts around the globe. We have used this API to pull some of the stories and display them to the client. An API key is required to use this REST API, see below to see how to get one.
- IPAPI
A helpful and powerful API, IPAPI takes an IP address and returns a whole host of information that can help us do many things. For this project, we used this API to get the correct location of the client in longitude and latitude form.
- Ipify
Simple and easy to use, this REST API can give easily gives us the client's IP address. We have used this API in conjunction with IPAPI to get the client's location in longitude and latitude form.
- XKCD
Humorous and thought-provoking, the XKCD API allows us to pull straight from xkcd and display a memorable comic for the client.
When you are ready, go to your terminal and change your directory to where your would like to clone the repo, then run the below command:
git clone https://github.com/PGreatness/import-Greatness.git
This will make a HTTPS clone of the repo. Another option is to download the ZIP folder after clicking Clone or download
on GitHub, then extracting it to your desired location.
This project requires the dependencies listed on the Dependencies section in order to run. Please have them downloaded before continuing.
In order to make use of The Daily Bugle, you will need the API keys for the APIs that require one. So far, you will need 2 API keys. For these, the links to get the API keys are listed below:
Before we delve into the explanation, it is imperative that you are in the correct build. Open a terminal and run the following command to go to the distribution build.
cd path/to/repo/The/ Daily/ Bugle/distr/
This build has a keys.json
file located in data/API_Keys
. Open a terminal in the data/API_Keys
folder and run these commands to replace the placeholders with your API Keys. Remember to activate your virtual environment
to aviod any collatoral damage.
source path/to/virtual/environment/Scripts/activate #for Windows
. path/to/virtual/environment/bin/activate #for Linux/OS
nano keys.json
From there, enter your API keys by overwriting the placeholder, Your_DarkSky_API_Key
overwritten by your DarkSky API key and Your_NYTimes_API_Key
overwritten by your New York Times API Key. The quotation marks("") are required and must not be deleted.
If you do not have either of the keys, look at the subsection below to on how to get the keys.
Click here to go to the DarkSky API
Click on Sign Up
, and register for an account. After this, you should be given an API key. Copy this key into your clipboard and go to the terminal.
Run the following command to open the JSON file.
nano keys.json
With the JSON file open, replace Your_DarkSky_API_Key
with your DarkSky API key.
{
"Weather" : "Your_DarkSky_API_Key"
}
Click here to go the New York Times API
Click on Get API Key
in the top right corner. Fill out the required information and, where it asks for the API, select Top Stories
. This is a very important part since The Daily Bugle will not work without the correct API selected.
Afterwards, click on Create API Key
. Your API key should appear in your email shortly. Copy the API and go back to the terminal to execute this command.
nano keys.json
Your JSON file should look like this at this point:
{
"Weather" : "Your_DarkSky_API_Key"
}
Replace Your_NYTimes_API_Key
with your New York Times API key. Remember that the quotation marks("") are required and should not be deleted.
{
"Weather" : "Your_DarkSky_API_Key",
"News" : "Your_NYTimes_API_Key"
}
It is important to note that the order in which the Weather
and News
appear is irrelevant.
Now your program is ready to go! On your terminal, run the following commands:
cd path/to/project/dir/The/ Daily/ Bugle/distr
python app.py
This should cause the following to appear:
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Now go to your favorite browser and paste this into the URL:
http://127.0.0.1:500/
This will take you to the localhost
where your can the project working in all of its glory!
Although not one of the biggest projects, The Daily Bugle still uses quite a few modules. For a more exhaustive list, along with tested versions, see the Requirements plaintext file.
If you wish to download all of the modules listed below, you can do so easily. First, make sure that you have Python
. Run the following in your terminal:
python --version
This should return the current version of Python installed on your computer. Please note that you will need Python 3.0.0 or greater to run this project.
If you do not have Python, you can download the latest version here, which should come with pip
installed.
To recursively download the required modules, run the following commands:
cd path/to/cloned/repo
pip install -r < requirements.txt
This will change the current working directory to the cloned repo directory, then recursively install all the dependencies listed in the requirements.txt file located in the root of the repo directory. Note: This assumes that you do not have a virtual environment to work in. If you do, please do activate it or create a new environment in order to keep your current versions.
- urllib
urllib
has been used to get the JSON files from each of the APIs. It is used extensively and is an important part of the project. It is a standard library from Python and require no further action.
- pip
pip
has been used to install all the extra modules like flask
and virtualenv
. Python (versions 2 to 2.7.9 or 3 and beyond) come with pip installed automatically.
- venv
venv
is used to avoid collateral damage from running the program. In essence, it provides a buffer that protects your current computer state by on a seperate, isolated environment. If you are using Python 3.0.0 or higher, skip to the next step as virtualenv
comes pre-installed. If you are using any Python distribution prior to 3.0.0, run the following in your terminal to create a virtual environment, replacing Name_Of_Environment with your desired name of the environment:
pip install virtualenv
virtualenv Name_Of_Environment
For Python3 or higher, run the following in your terminal, replacing Name_Of_Environment with your desired name of the environment:
python -m venv Name_Of_Environment
You can then activate the virtual environment by running the following in your terminal, again replacing Name_Of_Environment with your virtual environment name:
For Linux/OS:
. Name_Of_Environment/bin/activate
For Windows:
source Name_Of_Environment\Scripts\activate
- Python3
Python3
is required to run this project. It is written in Python. If you do not have Python, you can download it here. It is recommended to get the latest version (at the time of writing, it is 3.7.1).
- os
os
is a simple library that is used to generate session keys for unique users. It is a standard library from Python and requires no further action.
- json
The json
library is used to parse through the JSON files returned by the API calls. It is a standard library from Python and requires no further action.
- flask
flask
is the library that runs the app and allows it to be hosted on localhost
. It is required for the project to work correctly. In order to install flask,
run the following command:
pip install flask
- wheel
wheel
is an important part of the app and goes hand in hand with flask
. To install wheel, run the following command:
pip install wheel
- Jinja2
jinja2
is used to set up templates for the multiple HTML files. It is required by flask
. To install Jinja2, run the following command:
pip install jinja2
- passlib
passlib
provides the password hashing and encrpyting services required to store passwords. It can be installed using the command below:
pip install passlib
- Datetime
Datetime
is a Python libary used to get the current date and time. This is used to set limits on refreshes to avoid rate limits being exceeded. It can be installed with the following command:
pip install datetime