This repository was archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbusted_xml.rb
More file actions
188 lines (157 loc) · 5.38 KB
/
busted_xml.rb
File metadata and controls
188 lines (157 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Copyright: Kit Plummer
# http://creativecommons.org/licenses/by-sa/3.0/us/
require 'bus'
require 'stop'
require 'route'
require 'station'
module BustedXml
def BustedXml.trace_kml(route)
response = HTTParty.get("http://www.suntran.com/webwatch/Scripts/Route#{route}_trace.js")
js_trace = response.body.split('*')[1].split('|')
builder = Builder::XmlMarkup.new
builder.instruct!
builder.comment! "proxy service to access the SunTran WebWatch data."
kml = builder.kml(:xmlns => "http://www.opengis.net/kml/2.2") { |root|
root.Document { |doc|
doc.name "Route Number: #{route}"
doc.Style(:id => "yellowLineGreenPoly") { |ylgp|
ylgp.LineStyle { |line_style|
line_style.color "7fff0000"
line_style.width "4"
}
ylgp.PolyStyle { |poly_style|
poly_style.color "7fff0000"
}
}
js_trace.each { |line|
#puts "Line: " + line
doc.Placemark { |p|
p.styleUrl "#yellowLineGreenPoly"
p.LineString { |ls|
ls.extrude "1"
ls.tessellate "1"
ls.altitudeModel "absolute"
coords = ''
points = line.split(';')
points.each do |point|
coords = coords + "#{point.gsub(' ', ',')}\n"
end
ls.coordinates coords
}
}
}
}
}
end
def BustedXml.json(route, section)
response = HTTParty.get("http://www.suntran.com/webwatch/UpdateWebMap.aspx?u=#{route}")
res = response.body.split('*')
r = Route.new(res[0],route)
end
def BustedXml.xml(route, section)
response = HTTParty.get("http://www.suntran.com/webwatch/UpdateWebMap.aspx?u=#{route}")
res = response.body.split('*')
builder = Builder::XmlMarkup.new
builder.instruct!
builder.comment! "proxy service to access the SunTran WebWatch data."
xml = builder.route(:requested => res[0], :id => route) { |b|
# stations and departures
# 32.1634229|-110.9441526|IRVINGTON & CAMPBELL|South |7:46 AM<br>8:18 AM<br>8:46 AM<br>|7
if section == "all" || section == "stations" || section == "stops"
b.stations { |station|
s_stations = res[1].split(';')
s_stations.each do |s_station|
station.station { |s|
station_data = s_station.split('|')
s.name station_data[2]
s.lat station_data[0]
s.lng station_data[1]
s.direction station_data[3].chop
s.departures { |d|
deps = station_data[4].split('<br>')
deps.each do |dep|
d.time dep
end
}
}
end
}
end
# puts "SECTION #{section}"
# stops and departures
if section == "all" || section == "stops"
b.stops { |stop|
s_stops = res[3].split(';')
s_stops.each do |s_stop|
stop.stop { |s|
stop_data = s_stop.split('|')
s.name stop_data[2]
s.lat stop_data[0]
s.lng stop_data[1]
s.direction stop_data[3].chop
s.departures { |d|
deps = stop_data[4].split('<br>')
deps.each do |dep|
d.time dep
end
}
}
end
}
end
# busses
# Bus: 32.1898495|-110.9292197|2|<b>South </b><br>Next Timepoint: FORGEUS AT PRESIDENT (KINO HOSP)
# Bus direction contains unnecessary markup
if section == "all" || section == "busses"
s_busses = res[2].split(';')
b.busses { |bus|
s_busses.each do |s_bus|
bus_data = s_bus.split('|')
bus.bus { |b|
b.lat bus_data[0]
b.lng bus_data[1]
b.direction bus_data[3].split('<br>')[0].gsub(/<\/?[^>]*>/, "").strip
b.comment! "No clue what Next Timepoint is???"
b.destination bus_data[3].split('<br>')[1]
}
end
}
end
}
return xml
end
def BustedXml.kml(route, section)
response = HTTParty.get("http://www.suntran.com/webwatch/UpdateWebMap.aspx?u=#{route}")
res = response.body.split('*')
builder = Builder::XmlMarkup.new
builder.instruct!
builder.comment! "proxy service to access the SunTran WebWatch data."
kml = builder.kml(:xmlns => "http://www.opengis.net/kml/2.2") { |root|
root.Document { |doc|
doc.name "Route Number: #{route}"
doc.Style(:id => "busMark") { |style|
style.IconStyle { |iconstyle|
iconstyle.Icon { |icon|
icon.href "../../../images/BusEast.png"
}
}
}
if section == "all" || section == "busses"
s_busses = res[2].split(';')
s_busses.each do |s_bus|
bus_data = s_bus.split('|')
doc.Placemark { |p|
p.styleUrl "#busMark"
p.name "Bus on Route #{route}"
p.comment! "No clue what Next Timepoint is???"
p.description bus_data[3].split('<br>')[1]
p.Point { |point|
point.coordinates "#{bus_data[1]},#{bus_data[0]},0"
}
}
end
end
}
}
end
end