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.
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:
- Prints the current temperature for the zipcode.
- Prints the forecast for the next 3 days.
- Prints the hours that will have nice weather and will not.
- Allows the zipcode to be reset to a different zipcode.
- Exits the script.
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.
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.
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.