A Django site.
November 20, 2008

Hans Fugal
no nic
The Fugue :
» Feed Me

Our first frost should come any time now, and I want to have warning of it so we can rescue our tomatoes. Well, I have a link to the NWS Area Forecast Discussion in my bookmarks which I try to read every day, but some days I forget. What I need is a feed. But as far as I can tell only Honolulu is cool enough to get a feed for AFDs. Weird. So what I needed was to create a feed from an existing web page.

I thought I would find a website that offers a service like this but I didn't (in a few short minutes of searching). I found websites that came halfway, but they were very complicated to set up and/or they didn't display the body of the page, only a link. The whole point is that I want to read it in my feed reader!

So I whipped up this Ruby code (standard libs only, no gems required):

#! /usr/bin/ruby
require 'erb'
require 'open-uri'
require 'ostruct'

# configuration
channel = OpenStruct.new(:url => "http://www.srh.noaa.gov/data/EPZ/AFDEPZ",
                         :title => "EPZAFD",
                         :description => "National Weather Service Area Forecast Discussion, El Paso TX/Santa Teresa NM")
item = OpenStruct.new(:url => channel.url,
                      :title => "Area Forecast Discussion",
                      :date => Time.now)

# fetch the page
afd = open(item.url)
item.date = afd.last_modified unless afd.last_modified.nil?
item.body = "<pre>" + afd.read + "</pre>"

# emit
include ERB::Util
template = ERB.new <<EOF
Content-Type: application/rss+xml

<?xml version="1.0"?>
<rss version="2.0">
   <channel>
      <title><%= h channel.title %></title>
      <link><%= h channel.url %></link>
      <description><%= h channel.description %></description>
      <lastBuildDate><%= h Time.now.rfc822 %></lastBuildDate>
      <generator>feedme</generator>
      <item>
         <title><%= h item.title %></title>
         <description><%= h item.body %></description>
         <pubDate><%= h item.date.rfc822 %></pubDate>
         <guid><%= h "#{channel.url}?date=#{item.date.iso8601}" %></guid>
      </item>
   </channel>
</rss>
EOF
puts template.result(binding)

Nothing overly fancy here. I use open-uri to fetch the page, extract the Last-Modified header (if it exists) and shoehorn it into an ERB template for the RSS.

In this case I just made it executable and slapped a Content-Header before the output and call it as a CGI. You could just as well run a cron job to update a file on disk (In which case remove the Content-Header from the template).

Once I found the pure text version of the AFD, it was just a matter of slapping it between <pre> tags, but if you had some actual screen scraping to do you might want to look at Hpricot which makes that really easy. In particular, I could have used the URL http://www.crh.noaa.gov/product.php?site=NWS&issuedby=EPZ&product=AFD&format=txt&version=1&glossary=1 and done

...
require 'hpricot'
...
item.body = (doc/"#content").to_html

which is in fact how I started out. But this page doesn't have a Last-Modified header which means my feed reader would always show it as a new item (every time the cron job updated, or every time I hit the CGI script, either way). Luckily I found the text-only URL that doesn't have this problem.

July 30, 2007

Jeremy Robb
scothoser
Scothoser's Corner
» Google and the Open Wireless Networks Goal

This morning, as I drove 10 miles out of my way to avoid an accident that wasn't reported on traffic radio (which is a gripe for another day), I tuned into NPR for Morning Addition. I love public radio, because the news is probably the least biased that I have ever heard (yet still very biased). It's refreshing to hear about events that most major news groups would see beneath them, such as the existence of Rose Shows.

This particular morning they had This article on Google's efforts to urge the FCC to open wireless networks to more competition outside of the "Big Four". The reason behind it is sound: In the wake of a possible failure of the Net Neutrality situation, Google wants to secure the future of wireless networks by making their applications, search engines, etc. available for everyone who want to use it. It's a boost for business in a growing market, and provides good PR for Google.

Another really good reason I heard Google mention on Friday was the need for real competition within the Wireless Network community. Right now, you have the Big Four: Sprint, Verizon, T-Mobile, and AT&T.; There are other, smaller networks, but they are marginalized by these big competitors. A lot of it has to do with existing network presence, limited radio bandwidth availability because of funding, and so on. Sound familiar? Ma Bell had the same setup, and continues to have the same setup with service monopolies in areas where they own the infrastructure.

So what's the answer? provide a public infrastructure. Google is trying to convince the FCC of this through their auctions. It would force the winning bidders to provide access to these air waves to allow other networks to utilize them. Hence better network support, better customer service, better consumer experiences.

Sounds very similar to the arguments that initiated the UTOPIA project in various Utah cities. And the same arguments are being made against Google's initiative: Bidding will not go as high, and the FCC will take a hit on how much money they will make, ultimately hurting the tax payer in the short run. So Google offered the answer: Guarantee a bid that will be attractive to the FCC and make the potential loss go away. The same attempt was done by various businessmen in Salt Lake to convince the Salt Lake Council to go with UTOPIA.

I wish Google success in this endeavor. Perhaps they can create a change in the wireless community that will make me want to have a cell phone. Perhaps they can convince an increasingly consumer-hostile business to release their strangle-hold on the market to allow for real competition to emerge, and by doing so provide an air of innovation that will make wireless a network worth innovating in.