#63 Keeping Track of the Weather

Another straightforward use of website scraping that illustrates yet a different approach is a weather forecast tool. Specify a zip code, and this script goes to the Census Bureau to obtain population and latitude/longitude information. It visits AccuWeather to extract the current weather in that region.

The Code

 #!/bin/sh # weather - Reports the weather forecast, including lat/long, for a zip code. llurl="http://www.census.gov/cgi-bin/gazetteer?city=&state=&zip=" wxurl="http://wwwa.accuweather.com" wxurl="$wxurl/adcbin/public/local_index_print.asp?zipcode=" if [ "$1" = "-a" ] ; then size=999; shift else size=5 fi if [ $# -eq 0 ] ; then echo "Usage: $0 [-a] zipcode" >&2 exit 1 fi if [ $size -eq 5 ] ; then ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.