10
attr_reader :long, :lat, :priority, :station
12
def initialize(number)
14
@url = 'http://newsrss.bbc.co.uk/weather/forecast/' + @id + '/ObservationsRSS.xml'
18
xmlData = Net::HTTP.get_response(URI.parse(@url)).body
20
data = XmlSimple.xml_in(xmlData, { 'KeyAttr' => 'name' })
21
rescue REXML::ParseException
25
channel = (data["channel"])[0]
27
name = channel["title"].to_s.sub( /BBC - Weather Centre - Latest Observations for /, "" )
28
nameList = name.split( /, / )
29
@station = nameList[0].to_s
30
@country = nameList[1].to_s
32
item = channel["item"][0]
33
@lat = item['lat'].to_s.to_f
34
@long = item['long'].to_s.to_f
35
if @lat == "N/A" or @long == "N/A"
47
string += @station.to_s
50
string += @country.to_s
62
string = "<Station>\n"
63
string += " <name>" + @station + "</name>\n"
64
string += " <Country>" + @country + "</Country>\n"
65
string += " <id>" + @id.to_s + "</id>\n"
66
string += " <priority>" + @priority.to_s + "</priority>\n"
67
string += " <Point>\n"
68
string += " <coordinates>" + @long.to_s + "," + @lat.to_s + "</coordinates>\n"
69
string += " </Point>\n"
70
string += "</Station>\n"
74
# def priority=(newPriority)
75
# @priority = newPriority
78
def angelDistance(other)
80
distance = Math.acos( Math.sin( @lat / 180 * Math::PI ) * Math.sin( other.lat / 180 * Math::PI ) + Math.cos( @lat / 180 * Math::PI ) * Math.cos( other.lat / 180 * Math::PI ) * Math.cos( other.long / 180 * Math::PI - @long / 180 * Math::PI ) ).abs
88
puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
90
stations = Array.new()
91
1.upto( 8000 ) do |i| # Should be about 8000
92
station = Station.new( i )
94
minDist = 2.0 * Math::PI
95
minDistStation = "none"
96
stations.each do |other|
97
distance = station.angelDistance( other )
100
minDistStation = other.station
106
while minDist < min and priority > 0
111
station.priority = priority
115
stations = stations << station
118
puts "</StationList>"