source: freethepostcode.org/html/ruby/rss.rbx @ 726

Last change on this file since 726 was 726, checked in by Dominic Hargreaves, 10 years ago

initial import

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/usr/bin/ruby
2require 'cgi'
3require 'dao.rb'
4require 'rexml/document'
5require 'time'
6
7include REXML
8
9dao = OSM::Dao.instance
10cgi = CGI.new
11
12latitude = cgi['latitude'].to_f
13longitude = cgi['longitude'].to_f
14
15res = dao.call_sql { "select part1, part2, lat, lon, date from codes where confirmed = 1 order by date desc limit 10;" }
16
17
18  description = 'New postcodes entered at freethepostcode.org'
19
20  rss = Element.new 'rss'
21  rss.attributes['version'] = "2.0"
22  rss.attributes['xmlns:geo'] = "http://www.w3.org/2003/01/geo/wgs84_pos#"
23  channel = Element.new 'channel', rss
24  title = Element.new 'title', channel
25  title.text = description
26  description_el = Element.new 'description', channel
27  description_el.text = description
28  link = Element.new 'link', channel
29  link.text = 'http://www.openstreetmap.org/'
30
31  image = Element.new 'image', channel
32  url = Element.new 'url', image
33  url.text = "http://www.openstreetmap.org/feeds/mag_map-rss2.0.png"
34  title = Element.new 'title', image
35  title.text = "OpenStreetMap"
36  width = Element.new 'width', image
37  width.text = 100
38  height = Element.new 'height', image
39  height.text = 100
40  link = Element.new 'link', image
41  link.text = 'http://www.openstreetmap.org/'
42 
43  res.each_hash do |row|
44    item = Element.new 'item', channel
45
46    lat = sprintf("%0.10f", row['lat'])
47    lon = sprintf("%0.10f", row['lon'])
48    postcode = row['part1'] + ' ' + row['part2']
49
50    title = Element.new 'title', item
51    title.text = postcode
52
53    link = Element.new 'link', item
54    link.text = "http://www.freethepostcode.org/geocode?lat=#{lat}&lon=#{lon}"
55   
56    description = Element.new 'description', item
57    description.text = "Postcode #{postcode} at #{lat}/#{lon}"
58    pubDate = Element.new 'pubDate', item
59    pubDate.text = Time.parse( row['date'])
60
61    lat_el = Element.new 'geo:lat', item
62    lat_el.text = lat
63    lon_el = Element.new 'geo:long', item
64    lon_el.text = lon
65  end
66
67puts rss.to_s
Note: See TracBrowser for help on using the repository browser.