I just said what I said and it was wrong
Or was taken wrong

Iridium flares are momentary bright reflections of sunlight off the polished antennae of the Iridium satellites. They can be as bright as magnitude -8 and last as long as a few seconds. There’s usually a good one every few days, and they’re fun to go out and see on clear nights—even more fun if you go out with your kids. Predictions of the time and position of up to a week’s worth of flares (and of other satellite crossings) are available at Heavens Above. To make the most of Heavens Above, you should create an account and have it save your latitude and longitude.

While it’s nice to be able to go to Heavens Above and look up the next set of flares, I thought it would be even better to have the information sent to me. Heavens Above doesn’t have an alert service, so I decided to make one of my own, scraping the information off its page and emailing it to me once a week.

The bulk of the work is done by this script, which I call iridium.py. It uses the Python mechanize module to automate the login procedure, grab the table of data from the Iridium flares web page, wrap that table in some HTML and CSS, and set up mail header that sendmail understands.

Lines 6–9 customize the script for a particular user. You’ll want to change the email addresses and the Heavens Above username and password. Lines 18–25 create a virtual browser and log in to the site. The site responds by sending the browser to the site’s home page, but with a special session ID string appended to the URL. We grab that session ID for our subsequent browsing.

Lines 30–39 open the Iridium page, extract the data table, and convert all the relative URLs in the table’s links to absolute URLs. This is the sort of thing I would normally do with the Beautiful Soup parsing library, but for some reason, Beautiful Soup chokes on the Heavens Above HTML. So I just did a couple of straightforward splits on the HTML to isolate the data table.

The rest of the script consists of the HTML wrapper code and the mail headers. To send myself an email with the Iridium flare schedule, I run

python /path/to/iridium.py | /usr/sbin/sendmail -t

and I get a nicely formatted email of the schedule, which looks like this in Mail.app

and like this on the iPhone

The table is a little wide for the iPhone, even in landscape mode, but it’s easy enough to read and the links work.

There are several ways to use this code. As it stands, I’ll use Lingon to set up a launchd process that runs the above command every Monday morning and sends me the schedule for the upcoming week. But it would be relatively simple to eliminate the mail headers and wrap the HTML with RSS headers to turn it into a news feed. A more substantial modification could search the table for especially bright flares and send an email or targeted Twitter message on those days.