Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes bug which I don't understand.

  • Loading branch information...
commit 0da6ed80f54811de9ffde610e20eadc0fdcb3b5c 1 parent 796d46f
Stanisław Wasiutyński authored

Showing 2 changed files with 21 additions and 15 deletions. Show diff stats Hide diff stats

  1. +3 1 Rakefile
  2. +18 14 bin/import/stops/jakdojade.rb
4 Rakefile
@@ -5,6 +5,8 @@ require 'rake'
5 5 require 'yaml'
6 6 require 'json'
7 7 require 'restclient'
  8 +
  9 +require './bin/import/stops/jakdojade'
8 10 #require 'spec/rake/spectask'
9 11
10 12 #task :default => :test
@@ -44,7 +46,7 @@ namespace :couchdb do
44 46 when 'kzkgop'
45 47 `node kzkgop.js`
46 48 when 'jakdojade'
47   - `node jakdojade.js #{city} | ruby jakdojade.rb #{args[:db]}`
  49 + JakDojade.save!(args[:db], `node jakdojade.js #{city}`)
48 50 else
49 51 raise 'Unknown source'
50 52 end
32 bin/import/stops/jakdojade.rb
@@ -5,20 +5,24 @@
5 5 require 'couchrest'
6 6 require 'time'
7 7
8   -db = CouchRest.database "http://localhost:5984/#{ARGV[0]}" # TODO: read it from config/database
9   -all = JSON.parse($stdin.read[4..-3].sub('].concat([',',').sub('],[',','))
10   -a, b, stops, x, y = all.slice!(-5..-1)
  8 +class JakDojade
  9 + def self.save!(db, data)
  10 + db = CouchRest.database "http://localhost:5984/#{db}" # TODO: read it from config/database
  11 + all = JSON.parse(data[4..-3].sub('].concat([',',').sub('],[',','))
  12 + a, b, stops, x, y = all.slice!(-5..-1)
11 13
12   -all.each_slice(25) do |slice|
13   - index = slice[11]
14   - type = stops[slice[10]-1]
15   - next unless ['bus','tram'].include?(type)
  14 + all.each_slice(25) do |slice|
  15 + index = slice[11]
  16 + type = stops[slice[10]-1]
  17 + next unless ['bus','tram'].include?(type)
16 18
17   - doc = {type: 'Stop', updated_at: Time.new.utc.xmlschema, location: {}}
18   - doc[:location][:lat], doc[:location][:lon] = slice[4..5]
19   - doc[:address] = (index === 0 ? stops[slice[22]-1] : stops[index-1]).force_encoding('UTF-8')
20   - doc[:name] = stops[slice[17]-1].force_encoding('UTF-8')
21   - doc[:operates] = [type]
22   -
23   - db.save_doc doc
  19 + doc = {type: 'Stop', updated_at: Time.new.utc.xmlschema, location: {}}
  20 + doc[:location][:lat], doc[:location][:lon] = slice[4..5]
  21 + doc[:address] = (index === 0 ? stops[slice[22]-1] : stops[index-1]).force_encoding('UTF-8')
  22 + doc[:name] = stops[slice[17]-1].force_encoding('UTF-8')
  23 + doc[:operates] = [type]
  24 +
  25 + db.save_doc doc
  26 + end
  27 + end
24 28 end

0 comments on commit 0da6ed8

Please sign in to comment.
Something went wrong with that request. Please try again.