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