August 29, 2015 at 4:23 PM by Dr. Drang
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.
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.
The CGI script,
wunder.py, takes the latitude and longitude as parameters and generates a web page with
- A local radar image centered 1° west of the location. I’m used to weather coming from the west.
- The current conditions and today’s sunrise and sunset.
- The forecast for the next twelve hours, given at three-hour intervals.
- Forecasts for the next two days, given at four-hour intervals.
The script requires a Weather Underground key that’s saved in the
wukey variable on Line 187.
The HTML file,
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
-xx.xxx are the latitude and longitude of the location in decimal degrees. After the page loads, use the Share button and the 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
in Safari. Because of the commenting/uncommenting, it won’t show any weather data, but that’s OK. Go ahead and useagain 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.