rzd 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/rzd +18 -6
- data/lib/rzd.rb +7 -0
- data/lib/rzd/coach.rb +3 -0
- data/lib/rzd/commands/get_coaches.rb +34 -0
- data/lib/rzd/version.rb +1 -1
- metadata +6 -4
data/bin/rzd
CHANGED
@@ -1,19 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
unless ARGV[0] && ARGV[1] && ARGV[2]
|
4
|
-
puts 'Usage: rzd [FROM] [TO] [DAY.MONTH]'
|
4
|
+
puts 'Usage: rzd [FROM] [TO] [DAY.MONTH] [TRAIN]'
|
5
5
|
exit
|
6
6
|
end
|
7
7
|
|
8
8
|
require 'rubygems'
|
9
9
|
require 'rzd'
|
10
10
|
|
11
|
-
|
11
|
+
if ARGV[3]
|
12
|
+
coaches = Rzd.get_coaches( ARGV[0], ARGV[1], ARGV[2], ARGV[3] )
|
12
13
|
|
13
|
-
if
|
14
|
-
|
14
|
+
if coaches.empty?
|
15
|
+
puts " -- "
|
16
|
+
else
|
17
|
+
coaches.each do |coach|
|
18
|
+
puts "#{coach.num} \t#{coach.type} \t#{coach.cost} \t#{coach.seats[:all]}"
|
19
|
+
end
|
20
|
+
end
|
15
21
|
else
|
16
|
-
trains.
|
17
|
-
|
22
|
+
trains = Rzd.get_trains( ARGV[0], ARGV[1], ARGV[2] )
|
23
|
+
|
24
|
+
if trains.empty?
|
25
|
+
puts " -- "
|
26
|
+
else
|
27
|
+
trains.each do |train|
|
28
|
+
puts "#{train.num} \t#{train.name} \t#{train.seat_table}"
|
29
|
+
end
|
18
30
|
end
|
19
31
|
end
|
data/lib/rzd.rb
CHANGED
@@ -10,7 +10,14 @@ class Rzd
|
|
10
10
|
Rzd::Commands::GetTrains.new.execute( from, to, date )
|
11
11
|
end
|
12
12
|
|
13
|
+
def get_coaches( from, to, date, train )
|
14
|
+
require 'rzd/commands/get_coaches'
|
15
|
+
|
16
|
+
Rzd::Commands::GetCoaches.new.execute( from, to, date, train )
|
17
|
+
end
|
18
|
+
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
16
22
|
require 'rzd/train'
|
23
|
+
require 'rzd/coach'
|
data/lib/rzd/coach.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class Rzd::Commands::GetCoaches
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@agent = Mechanize.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute( from, to, date, train )
|
10
|
+
page = @agent.get "http://pass.rzd.ru/isvp/public/pass/express?route_id=&schd_id=6&action=submit&schd_ref_id=1&refererLayerId=4922&STRUCTURE_ID=735&layer_id=4923&src=#{CGI::escape from}&dst=#{CGI::escape to}&date=#{CGI::escape date}&train=#{CGI::escape train}"
|
11
|
+
table = page.parser.css('form table.result').first
|
12
|
+
if table
|
13
|
+
rows = table.css('tr')
|
14
|
+
rows.shift
|
15
|
+
rows.shift
|
16
|
+
rows.map do |row|
|
17
|
+
cells = row.css('td')
|
18
|
+
|
19
|
+
seat_types = [:upper,:lower,:upper_side,:lower_side,:other]
|
20
|
+
seats = {}
|
21
|
+
cells[7..11].each_with_index do |c,i|
|
22
|
+
s = c.text.gsub("\302\240", "").strip.to_i
|
23
|
+
seats[seat_types[i]] = s unless s == 0
|
24
|
+
end
|
25
|
+
seats[:all] = seats.values.inject(0, :+)
|
26
|
+
|
27
|
+
Rzd::Coach.new cells[1].text.strip.gsub(/\n[\s\302\240]+/,' '), cells[5].text.strip, cells[6].text.strip, seats
|
28
|
+
end
|
29
|
+
else
|
30
|
+
[]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/rzd/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rzd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexey Noskov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-28 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -45,6 +45,8 @@ extra_rdoc_files:
|
|
45
45
|
files:
|
46
46
|
- lib/rzd.rb
|
47
47
|
- lib/rzd/commands/get_trains.rb
|
48
|
+
- lib/rzd/commands/get_coaches.rb
|
49
|
+
- lib/rzd/coach.rb
|
48
50
|
- lib/rzd/version.rb
|
49
51
|
- lib/rzd/train.rb
|
50
52
|
- bin/rzd
|