rzd 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +11 -0
- data/bin/rzd +19 -0
- data/lib/rzd.rb +16 -0
- data/lib/rzd/commands/get_trains.rb +35 -0
- data/lib/rzd/train.rb +14 -0
- data/lib/rzd/version.rb +9 -0
- metadata +95 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alexey Noskov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
= Rzd
|
2
|
+
|
3
|
+
Rzd is a gem automating checking ticket information for russian railway service rzd.ru.
|
4
|
+
|
5
|
+
== Contributors
|
6
|
+
|
7
|
+
* Alexey Noskov (http://github.com/alno)
|
8
|
+
|
9
|
+
Feel free to request pull of new providers.
|
10
|
+
|
11
|
+
Copyright (c) 2011 Alexey Noskov, released under the MIT license
|
data/bin/rzd
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless ARGV[0] && ARGV[1] && ARGV[2]
|
4
|
+
puts 'Usage: rzd [FROM] [TO] [DAY.MONTH]'
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'rzd'
|
10
|
+
|
11
|
+
trains = Rzd.get_trains( ARGV[0], ARGV[1], ARGV[2] )
|
12
|
+
|
13
|
+
if trains.empty?
|
14
|
+
puts " -- "
|
15
|
+
else
|
16
|
+
trains.each do |train|
|
17
|
+
puts "#{train.num} \t#{train.name} \t#{train.seat_table}"
|
18
|
+
end
|
19
|
+
end
|
data/lib/rzd.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class Rzd::Commands::GetTrains
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@agent = Mechanize.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute( from, to, date )
|
10
|
+
page = @agent.get "http://pass.rzd.ru/isvp/public/pass/isvp/public/rzd/express?schd_id=1&action=submit&layer_id=4922&STRUCTURE_ID=735&src=#{CGI::escape from}&dst=#{CGI::escape to}&date=#{CGI::escape date}"
|
11
|
+
table = page.parser.css('form table')[2]
|
12
|
+
if table
|
13
|
+
rows = table.css('tr')
|
14
|
+
rows.shift
|
15
|
+
rows.map do |row|
|
16
|
+
cells = row.css('td')
|
17
|
+
|
18
|
+
Rzd::Train.new cells[2].text.strip, cells[3].text.strip, get_seats( cells[7..11].text )
|
19
|
+
end
|
20
|
+
else
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def get_seats( str )
|
28
|
+
seats = []
|
29
|
+
Rzd::Train::SEATS.each do |s|
|
30
|
+
seats << s if str.include? s
|
31
|
+
end
|
32
|
+
seats
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/rzd/train.rb
ADDED
data/lib/rzd/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rzd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alexey Noskov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-15 00:00:00 +04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mechanize
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Rzd is a gem automating checking ticket information for russian railway service rzd.ru. Now it allows to get available ticket types fro given cities and date.
|
36
|
+
email:
|
37
|
+
- alexey.noskov@gmail.com
|
38
|
+
executables:
|
39
|
+
- rzd
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.rdoc
|
44
|
+
- MIT-LICENSE
|
45
|
+
files:
|
46
|
+
- lib/rzd.rb
|
47
|
+
- lib/rzd/commands/get_trains.rb
|
48
|
+
- lib/rzd/version.rb
|
49
|
+
- lib/rzd/train.rb
|
50
|
+
- bin/rzd
|
51
|
+
- MIT-LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/alno/rzd
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --line-numbers
|
60
|
+
- --inline-source
|
61
|
+
- --title
|
62
|
+
- Rzd gem
|
63
|
+
- --main
|
64
|
+
- README.rdoc
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 23
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 3
|
85
|
+
- 6
|
86
|
+
version: 1.3.6
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.7
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Rzd is a gem automating checking ticket information for russian railway service rzd.ru.
|
94
|
+
test_files: []
|
95
|
+
|