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
|
# File 'lib/undergrounder/tube_scraper.rb', line 6
def self.start!
@agent = Mechanize.new
@agent.get('http://tubephotos.dannycox.me.uk/stationsbyline.html'); tube_name_list, final_list = [], []
@agent.page.search('.style5').each {|x| tube_name_list << x.first[1]} tube_name_list.uniq!.sort!
stations = @agent.page.search('.stationList')
stations.each do |element|
children = element.elements.children;
temp_tube_list, temp_list = [], []
children.each_with_index do |x, i| value = x.text.split("\n").join(" ") .gsub(" "," ") .gsub("&", "and") .gsub(/\(([^\)]+)\)/,'').rstrip if(value != "")
temp_list << value
end
end
temp_list.each_with_index do |prov,index|
if index + 1 < temp_list.size
temp_tube_list << { prov => temp_list[index+1] }
end
end
final_list << temp_tube_list if temp_tube_list.size > 0
end
final_list.each_with_index do |lines,index|
lines.unshift(tube_name_list[index].gsub("&","and"))
end
File.open(Dir.pwd + "/tube_list2.yml", 'w+') {|f| f.write(final_list.to_yaml) }
end
|