Via points and Stops by Suburb added
[bus.git] / maxious-canberra-transit-feed / 04-generateymlinclude.rb
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
#!/usr/bin/ruby
 
require 'highline.rb'
include HighLine
 
require 'rubygems'
require 'postgres'
require 'json'
require 'yaml'
require 'pp'
# make - { name: Civic Interchange Platform 1,stop_code: civic_platform_1, lat: -35.2794347, lng: 149.130588}
connbus = PGconn.connect("localhost", 5432, '', '', "bus", "postgres", "snmc")
 
f = File.open('cbrtable.yml.in.in')
header = f.readlines
f.close
 
File.open('cbrtable.yml.in', 'w') do |f2|  
        f2.puts header
        f2.puts "stops:\n";
        begin
                time_points = connbus.exec("SELECT * from timing_point ORDER BY name")
        rescue PGError => e
                puts "Error reading from DB #{e}"
                #conn.close() if conn
        end
        time_points.each do |time_point|
                #pp time_point
                # 0 = name
                # 1 = lat*100000
                # 2 = lng*100000
                #pp time_point[0]
                f2.puts "  - { name: #{time_point[0]},stop_code: #{time_point[0]}, lat: #{Float(time_point[1])/10000000}, lng: #{Float(time_point[2])/10000000}}"
        end
        begin
                stops = connbus.exec("SELECT * from stops")
        rescue PGError => e
                puts "Error reading from DB #{e}"
                #conn.close() if conn
        end
        stops.each do |stop|
                #pp stop
                # 0 = geoPo
                # 1 = lat*100000
                # 2 = lng*100000
                # 3 = name
                # 4 = suburb(s)
                #pp time_point[0]
                f2.puts "  - { name: #{stop[3]},stop_code: #{stop[0]}, lat: #{Float(stop[1])/10000000}, lng: #{Float(stop[2])/10000000}, zone_id: #{stop[4]} }"
        end
        f2.puts "routes:\n";
end