Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes bug which I don't understand.

  • Loading branch information...
commit 0da6ed80f54811de9ffde610e20eadc0fdcb3b5c 1 parent 796d46f
@Stanley authored
Showing with 21 additions and 15 deletions.
  1. +3 −1 Rakefile
  2. +18 −14 bin/import/stops/jakdojade.rb
View
4 Rakefile
@@ -5,6 +5,8 @@ require 'rake'
require 'yaml'
require 'json'
require 'restclient'
+
+require './bin/import/stops/jakdojade'
#require 'spec/rake/spectask'
#task :default => :test
@@ -44,7 +46,7 @@ namespace :couchdb do
when 'kzkgop'
`node kzkgop.js`
when 'jakdojade'
- `node jakdojade.js #{city} | ruby jakdojade.rb #{args[:db]}`
+ JakDojade.save!(args[:db], `node jakdojade.js #{city}`)
else
raise 'Unknown source'
end
View
32 bin/import/stops/jakdojade.rb
@@ -5,20 +5,24 @@
require 'couchrest'
require 'time'
-db = CouchRest.database "http://localhost:5984/#{ARGV[0]}" # TODO: read it from config/database
-all = JSON.parse($stdin.read[4..-3].sub('].concat([',',').sub('],[',','))
-a, b, stops, x, y = all.slice!(-5..-1)
+class JakDojade
+ def self.save!(db, data)
+ db = CouchRest.database "http://localhost:5984/#{db}" # TODO: read it from config/database
+ all = JSON.parse(data[4..-3].sub('].concat([',',').sub('],[',','))
+ a, b, stops, x, y = all.slice!(-5..-1)
-all.each_slice(25) do |slice|
- index = slice[11]
- type = stops[slice[10]-1]
- next unless ['bus','tram'].include?(type)
+ all.each_slice(25) do |slice|
+ index = slice[11]
+ type = stops[slice[10]-1]
+ next unless ['bus','tram'].include?(type)
- doc = {type: 'Stop', updated_at: Time.new.utc.xmlschema, location: {}}
- doc[:location][:lat], doc[:location][:lon] = slice[4..5]
- doc[:address] = (index === 0 ? stops[slice[22]-1] : stops[index-1]).force_encoding('UTF-8')
- doc[:name] = stops[slice[17]-1].force_encoding('UTF-8')
- doc[:operates] = [type]
-
- db.save_doc doc
+ doc = {type: 'Stop', updated_at: Time.new.utc.xmlschema, location: {}}
+ doc[:location][:lat], doc[:location][:lon] = slice[4..5]
+ doc[:address] = (index === 0 ? stops[slice[22]-1] : stops[index-1]).force_encoding('UTF-8')
+ doc[:name] = stops[slice[17]-1].force_encoding('UTF-8')
+ doc[:operates] = [type]
+
+ db.save_doc doc
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.