New weather page

Last year, I wrote a CGI script in Python that generates a web page with just the weather information I want. It was a response to the plethora of weather apps for the iPhone that don’t quite do what I want. As I said,

This weather app doesn’t have Feature A; that app does, but it doesn’t have Feature B; this other app has both, but they’re inconveniently hidden behind a series of taps and swipes. What I want is a custom-built app that presents just the information I use in a format that’s convenient to me.

I recently updated the script to give a little more detail for the “tomorrow” and “day after tomorrow” forecasts, and I put it up on GitHub for people to download if they want to adjust it to their own needs.

I’ll reproduce the README below. If you need more detail, the original writeup is still largely correct.


Wunder

Weather information via the Weather Underground API. Intended for use on an iPhone, but I’m sure the GPS stuff can be adapted to Android.

CGI script

The CGI script, wunder.py, takes the latitude and longitude as parameters and generates a web page with

Weather page

The script requires a Weather Underground key that’s saved in the wukey variable on Line 187.

HTML file

The HTML file, wunderlocal.html, uses the iOS Geolocation class to access the GPS data via JavaScript and uses the latitude and longitude to construct a URL that calls wunder.py.

Both the wunder.py and wunderlocal.html must be put on a server where they’re accessible via a web browser. Depending on how your web server is configured, you may need to change the extension on wunder.py to make it executable. Whatever its name, you’ll need to edit Line 11 of wunderlocal.html to set the wURL variable to the URL of the CGI script.

Home screen buttons

To create a home screen button for a fixed location, just enter a URL of the form

http://path/to/wunder.py?lat=yy.yyy&lon=-xx.xxx

where yy.yyy and -xx.xxx are the latitude and longitude of the location in decimal degrees. After the page loads, use the Share button and the Add to Home Screen command to create an icon on your home screen that opens Safari immediately to the weather page for that location.

Creating a home screen button that gives you the weather for your current location is a little trickier. First, comment out the <script> in Lines 17–19 of wunderlocal.html. Then uncomment the <h1> on Line 21. Then go to

http://path/to/wunderlocal.html

in Safari. Because of the commenting/uncommenting, it won’t show any weather data, but that’s OK. Go ahead and use Add to Home Screen again to make an icon on your home screen linked to that URL.

Once you’ve made the home screen button, go back into wunderlocal.html and uncomment Lines 17–19 and comment out Line 21, putting the file back into its original state. Now when you tap the home screen button, it’ll redirect you to a weather info page for your current location. You’ll probably be asked for permission for the page to access your location.

Permission request