indian-rail 1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -10
- data/indian-rail.gemspec +3 -5
- data/lib/indian-rail.rb +0 -1
- data/lib/indian-rail/schedule.rb +66 -53
- metadata +18 -9
- data/lib/indian-rail/version.rb +0 -3
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Indian::Rail
|
2
2
|
|
3
|
-
|
3
|
+
Indian Rail is a simple wrapper for finding out India train details. Please see the documentation for the proper input arguments and expected output.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,12 +18,43 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
To enquire the PNR status of your journey *ticket*:
|
22
|
+
|
23
|
+
response = IndianRail::Pnr.enquiry "pnr_number"
|
24
|
+
|
25
|
+
Train Schedule methods will accept either train number or train name to find the schedule of a particular *Train*:
|
26
|
+
|
27
|
+
response = IndianRail::Schedule.find "train_number"
|
28
|
+
|
29
|
+
response = IndianRail::Schedule.find "train_name"
|
30
|
+
|
31
|
+
IndianRail will return a hash filled result something like this:
|
32
|
+
|
33
|
+
{:pnr=>"XXXXXXX", :train_no=>"XXXX", :train_name=>"EXP", :boarding_date=>"DD-MM-YYYY", :from=>"XXX", :to=>"YYY", :reserved_upto=>"XXX"}
|
34
|
+
|
35
|
+
You can even send proxy details, if you are working under proxy server
|
36
|
+
|
37
|
+
response = IndianRail::Schedule.find "train-number", :proxy => {:url => "proxy.example.com", :port => 'port_number'}
|
38
|
+
|
39
|
+
## MIT License
|
40
|
+
|
41
|
+
Copyright (c) 2013 Kalyan Allampalli
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
"Software"), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
57
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
58
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
59
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
60
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/indian-rail.gemspec
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'indian-rail/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |gem|
|
7
6
|
gem.name = %q{indian-rail}
|
8
|
-
gem.version =
|
7
|
+
gem.version = %q{1.0.1}
|
9
8
|
gem.authors = ["Kalyan Allampalli"]
|
10
9
|
gem.email = %q{kalyan.allampalli@gmail.com}
|
11
|
-
gem.description = %q{Client for the
|
10
|
+
gem.description = %q{Client for the Indian Rail Information}
|
12
11
|
gem.summary = %q{Indian Rail helps you get all the required information you want to know about Indian Railways.}
|
13
12
|
gem.homepage = %q{https://github.com/kalyanallampalli/indian-rail}
|
14
13
|
|
@@ -18,8 +17,7 @@ Gem::Specification.new do |gem|
|
|
18
17
|
"LICENSE.txt",
|
19
18
|
"README.md",
|
20
19
|
"Rakefile",
|
21
|
-
"lib/indian-rail.rb",
|
22
|
-
"lib/indian-rail/version.rb",
|
20
|
+
"lib/indian-rail.rb",
|
23
21
|
"lib/indian-rail/api.rb",
|
24
22
|
"lib/indian-rail/pnr.rb",
|
25
23
|
"lib/indian-rail/schedule.rb",
|
data/lib/indian-rail.rb
CHANGED
data/lib/indian-rail/schedule.rb
CHANGED
@@ -1,74 +1,87 @@
|
|
1
1
|
module IndianRail
|
2
|
-
class Schedule < Api
|
2
|
+
class Schedule < Api
|
3
3
|
def self.find(train_no=nil, options={})
|
4
4
|
response = {}
|
5
5
|
response[:message] = 'Please Enter Train Number or Name' and return response if train_no.nil?
|
6
6
|
begin
|
7
7
|
page_response = get_response([base_url_prefix, schedule_url_sufix].compact.join("/"), {:form_params => {'lccp_trnname' => train_no}}.merge!(options))
|
8
|
-
response = parse_train_details(page_response, train_no)
|
8
|
+
response = parse_train_details(page_response, train_no)
|
9
9
|
rescue Exception => e
|
10
10
|
response[:message] = "Service is not available - #{e.message}"
|
11
11
|
end
|
12
12
|
response
|
13
13
|
end
|
14
14
|
|
15
|
-
private
|
15
|
+
private
|
16
16
|
|
17
17
|
def self.parse_train_details(body, train_no)
|
18
|
-
page = Nokogiri::HTML(body)
|
19
|
-
data = {:train_no => train_no}
|
20
|
-
index = 1
|
18
|
+
page = Nokogiri::HTML(body)
|
21
19
|
tables = page.xpath('//table[@class="table_border_both"]')
|
22
20
|
details, train_detail = {}, {}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
[
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
table.css("tr:not([@class='heading_table_top'])").collect do |row|
|
42
|
-
coach_detail = {}
|
43
|
-
[
|
44
|
-
[:title, 'td[1]/text()'],
|
45
|
-
['1A', 'td[2]/text()'],
|
46
|
-
['2A', 'td[3]/text()'],
|
47
|
-
['FC', 'td[4]/text()'],
|
48
|
-
['3A', 'td[5]/text()'],
|
49
|
-
['CC', 'td[6]/text()'],
|
50
|
-
['SL', 'td[7]/text()'],
|
51
|
-
['2S', 'td[8]/text()'],
|
52
|
-
['3E', 'td[9]/text()']
|
53
|
-
].each do |name, xpath|
|
54
|
-
coach_detail[name] = row.at_xpath(xpath).to_s.strip
|
21
|
+
if tables.length == 3
|
22
|
+
runs_on = []
|
23
|
+
index = 1
|
24
|
+
coach_details, stn_details = [], [['Stn Code', 'Stn Name', 'Route No.', 'Arrival Time', 'Dep. time', 'Halt Time(In Min))', 'Distance', 'Day']]
|
25
|
+
tables.collect do |table|
|
26
|
+
if index == 1
|
27
|
+
table.css("tr:not([@class='heading_table_top'])").collect do |row|
|
28
|
+
[
|
29
|
+
[:train_no, 'td[1]/text()'],
|
30
|
+
[:train_name, 'td[2]/text()'],
|
31
|
+
[:runs_from, 'td[3]/text()']
|
32
|
+
].each do |name, xpath|
|
33
|
+
train_detail[name] = row.at_xpath(xpath).to_s.strip
|
34
|
+
end
|
35
|
+
(4..10).each do |day|
|
36
|
+
runs_on << row.at_xpath("td[#{day}]/text()").to_s.strip
|
37
|
+
end
|
38
|
+
train_detail[:runs_on] = runs_on.join(', ')
|
55
39
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
40
|
+
elsif index == 2
|
41
|
+
table.css("tr:not([@class='heading_table_top'])").collect do |row|
|
42
|
+
coach_detail = {}
|
43
|
+
[
|
44
|
+
[:title, 'td[1]/text()'],
|
45
|
+
['1A', 'td[2]/text()'],
|
46
|
+
['2A', 'td[3]/text()'],
|
47
|
+
['FC', 'td[4]/text()'],
|
48
|
+
['3A', 'td[5]/text()'],
|
49
|
+
['CC', 'td[6]/text()'],
|
50
|
+
['SL', 'td[7]/text()'],
|
51
|
+
['2S', 'td[8]/text()'],
|
52
|
+
['3E', 'td[9]/text()']
|
53
|
+
].each do |name, xpath|
|
54
|
+
coach_detail[name] = row.at_xpath(xpath).to_s.strip
|
55
|
+
end
|
56
|
+
coach_details << coach_detail
|
57
|
+
end
|
58
|
+
elsif index == 3
|
59
|
+
table.css("tr:not([@class='heading_table_top'])").collect do |row|
|
60
|
+
stn_detail = []
|
61
|
+
['td[2]/text()', 'td[3]/text()', 'td[4]/text()', 'td[5]/text()', 'td[6]/text()', 'td[7]/text()', 'td[8]/text()','td[9]/text()'].each do |xpath|
|
62
|
+
stn_detail << row.at_xpath(xpath).to_s.strip
|
63
|
+
end
|
64
|
+
stn_details << stn_detail
|
63
65
|
end
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
end
|
67
|
+
index += 1
|
68
|
+
end
|
69
|
+
details[:train_details] = train_detail
|
70
|
+
details[:coach_details] = coach_details
|
71
|
+
details[:stn_details] = stn_details
|
72
|
+
else
|
73
|
+
stn_details = [['Train Number', 'Train Name', 'Train Source', 'Dep.Time', 'Train Destination', 'Arr.Time']]
|
74
|
+
tables.collect do |table|
|
75
|
+
table.css("tr:not([@class='heading_table_top'])").collect do |row|
|
76
|
+
train_detail = []
|
77
|
+
['td[1]/input', 'td[2]/text()', 'td[3]/text()', 'td[4]/text()', 'td[5]/text()', 'td[6]/text()'].each_with_index do |xpath, i|
|
78
|
+
train_detail << (i == 0 ? row.at(xpath)['value'].to_i : row.at_xpath(xpath).to_s.strip)
|
79
|
+
end
|
80
|
+
stn_details << train_detail
|
81
|
+
end
|
82
|
+
end
|
83
|
+
details[:train_details] = stn_details.length == 1 ? 'Invalid Train name or data not exists' : details
|
84
|
+
end
|
72
85
|
details
|
73
86
|
end
|
74
87
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indian-rail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 1.5.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.9
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,8 +37,13 @@ dependencies:
|
|
32
37
|
version: 2.13.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.13.0
|
46
|
+
description: Client for the Indian Rail Information
|
37
47
|
email: kalyan.allampalli@gmail.com
|
38
48
|
executables: []
|
39
49
|
extensions: []
|
@@ -45,7 +55,6 @@ files:
|
|
45
55
|
- README.md
|
46
56
|
- Rakefile
|
47
57
|
- lib/indian-rail.rb
|
48
|
-
- lib/indian-rail/version.rb
|
49
58
|
- lib/indian-rail/api.rb
|
50
59
|
- lib/indian-rail/pnr.rb
|
51
60
|
- lib/indian-rail/schedule.rb
|
@@ -70,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
79
|
version: '0'
|
71
80
|
requirements: []
|
72
81
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.24
|
74
83
|
signing_key:
|
75
84
|
specification_version: 3
|
76
85
|
summary: Indian Rail helps you get all the required information you want to know about
|
data/lib/indian-rail/version.rb
DELETED