Skip to content

sterfry1988/Weather-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Weather-API

These are scripts that will compute and print the average temperature for the last seven days for San Jose, CA, and provide an interactive interface for a user to obtain weather information by zipcode.

Usage

In order to use the seven_day_sjc and interactive_forecast script you must have python version 2.7 installed. To call the seven_day_sjc script you may type:

python seven_day_sjc.py

in your terminal and the script will return the average mean temperature from the past 7 days. To use the interactive_forecast you may invoke the script by typing:

python interactive_forecast.py

You will then be prompted to enter a zipcode. Once you enter a zipcode the script will then give you 5 options:

Please select one of the following: 
 1) Current temperature. 
 2) Forecast over the next 3 days. 
 3) Is it a good day? 
 4) Reset ZIP code. 
 5) Exit 
 Enter your choice: 

Each option will execute the following behavior:

  1. Prints the current temperature for the zipcode.
  2. Prints the forecast for the next 3 days.
  3. Prints the hours that will have nice weather and will not.
  4. Allows the zipcode to be reset to a different zipcode.
  5. Exits the script.

Approach

The approach taken for this script was to use the free API at http://api.wunderground.com. This API gives free access to historical weather information and has good documentation.

Language

The language chosen for this script was to use Python. Python is an easy to read language which has many built-in libraries that makes accomplishing a task like this fun.

Implementation

The urllib2 library was used for creating a connection to the remote api and returning the request. The request will be converted to json which will allow the programmer to extract information in a standard way. This will also make reading and writing the request to a file easy. A common file was added so that the two scripts can take advantage of the same logic.

In order to save time on repeated calls and API quota the requests will be saved to disk. This allows for faster execution of the script in the event that the requests have been made already. Because the requests in the interactive script are testing realtime information there is a variable in common.py that will set a threshold, and a flag in checkCache_ to determine whether or not the API should be called.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages