rzdtc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6557606861079659b48e41866a807c695083c990
4
+ data.tar.gz: 62a774b1f60f4ecde0d4e156495ae7008cfad663
5
+ SHA512:
6
+ metadata.gz: e640ee9abaaa6c26716cbd35e168a49ac2e694938f0e76507c8019e5a295236efef7e566f5709460ddf6b59f1a3f65cdcf2bbdd0bce1a91ba1bfb707e8648064
7
+ data.tar.gz: 5ab99d406267748424a8f992dfb5b21ff8e1d315c9bab18c3fdc6a580e2baaabaa8bb7197d122a441206bb962d8fa2e88ea00e9d38adef5475dda13d06c6407e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rzdtc.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 kirqe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Rzdtc
2
+
3
+ Rzd tickets checker
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ Rzdtc.check_tickets('КРАСНОДАР', 'РОСТОВ', '24.11.2016')
9
+ ```
10
+
11
+ ```ruby
12
+ Rzdtc.check_tickets('КРАСНОДАР', 'РОСТОВ', '24.11.2016').first
13
+
14
+ # =>
15
+ [
16
+ {"date0"=>"24.11.2016", "varPrice"=>true,
17
+ "date1"=>"24.11.2016", "time0"=>"01:33", "time1"=>"06:04",
18
+ "trDate0"=>"23.11.2016", "trTime0"=>"14:00",
19
+ "deferredPayment"=>false, "route0"=>"СУХУМ",
20
+ "route1"=>"МОСКВА КАЗ", "number"=>"306С",
21
+ "number2"=>"306С", "typeEx"=>"0", "elReg"=>false,
22
+ "uid"=>"306SJ_1479940380000_1479956640000", "train_id"=>"0",
23
+ "bEntire"=>false, "carrier"=>"ФПК", "type"=>"0","station0"=>"КРАСНОДАР",
24
+ "station1"=>"РОСТОВ", "timeInWay"=>"04:31", "flMsk"=>"3",
25
+ "cars"=>[
26
+ {"freeSeats"=>"24", "itype"=>"4", "servCls"=>"2Л",
27
+ "tariff"=>"914", "pt"=>"273", "typeLoc"=>"Купе", "type"=>"Купе"},
28
+ {"freeSeats"=>"36", "itype"=>"1", "servCls"=>"3Л",
29
+ "tariff"=>"572", "pt"=>"171", "typeLoc"=>"Плацкартный", "type"=>"Плац"},
30
+ {"freeSeats"=>"14", "itype"=>"6", "servCls"=>"1Л",
31
+ "tariff"=>"1878", "pt"=>"562", "typeLoc"=>"СВ", "type"=>"Люкс"}
32
+ ]}
33
+ ]
34
+ ```
35
+
36
+
37
+ [MIT License](https://github.com/kirqe/rzdtc/blob/master/LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rzdtc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/rzdtc/base.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'httparty'
2
+ require 'active_support/core_ext/string/multibyte'
3
+
4
+ class Rzdtc::Base
5
+ include HTTParty
6
+
7
+ base_uri 'https://pass.rzd.ru'
8
+ default_timeout 5
9
+
10
+ def base_path
11
+ "/timetable/public/ru?STRUCTURE_ID=735&layer_id=5371&tfl=3&dir=0&checkSeats=1"
12
+ end
13
+
14
+ def get_city_id(city)
15
+ city = city.mb_chars.upcase.to_s
16
+ url = "http://rzd.ru/suggester?stationNamePart=#{URI.escape(city)}\
17
+ &lang=ru&lat=0&compactMode=y"
18
+
19
+ suggestions = self.class.get(url)
20
+ for suggestion in suggestions
21
+ if suggestion["n"] == city
22
+ return suggestion["c"]
23
+ end
24
+ end
25
+ nil
26
+ end
27
+
28
+ def check_tickets(from, to, date)
29
+ code0 = get_city_id(from)
30
+ code1 = get_city_id(to)
31
+ begin
32
+ date = Date.parse(date.to_s).strftime('%d.%m.%Y')
33
+ rescue ArgumentError, 'invalid date'
34
+ return
35
+ end
36
+
37
+ # from station
38
+ station0 = "&st0=#{URI.escape(from)}"
39
+ station_code0 = "&code0=#{code0}"
40
+ date0 = "&dt0=#{date}"
41
+
42
+ # to station
43
+ station1 = "&st1=#{URI.escape(to)}"
44
+ station_code1 = "&code1=#{code1}"
45
+
46
+ # first request to get rid and JSESSIONID
47
+ url1 = "#{base_path}#{station0}#{station_code0}#{date0}
48
+ #{station1}#{station_code1}".gsub(" ", "")
49
+
50
+ begin
51
+ resp = self.class.get(url1)
52
+ rescue URI::InvalidURIError, 'URI must be ascii only'
53
+ return
54
+ end
55
+ session_id = resp.headers["set-cookie"].split(",")[2].match('\JSESSIONID=(.*);')[1]
56
+ rid = JSON.parse(resp.body)['rid']
57
+
58
+ # add rid to first url and set session cookie
59
+ url2 = url1 + "&rid=#{rid}"
60
+ sleep(1)
61
+ result = self.class.get(url2, headers: {"Cookie" => "JSESSIONID=#{session_id}"})
62
+ data = JSON.parse(result.body)
63
+ if data['result'] == "Error"
64
+ []
65
+ else
66
+ data["tp"][0]["list"]
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Rzdtc
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rzdtc.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "rzdtc/version"
2
+ require "rzdtc/base"
3
+
4
+ module Rzdtc
5
+ def self.check_tickets(from, to, date)
6
+ Rzdtc::Base.new.check_tickets(from, to, date)
7
+ end
8
+ end
data/rzdtc.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rzdtc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rzdtc"
8
+ spec.version = Rzdtc::VERSION
9
+ spec.authors = ["kirqe"]
10
+ spec.email = ["railsr@yahoo.com"]
11
+
12
+ spec.summary = "Rzd tickets checker"
13
+ spec.description = "A gem for checking rzd train tickets"
14
+ spec.homepage = "http://github.com/kirqe/rzdtc"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "httparty", "~> 0.13.7"
27
+ spec.add_development_dependency "activesupport", "~> 5.0"
28
+ spec.add_development_dependency "rspec", "~> 3.4.0"
29
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rzdtc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kirqe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.4.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.4.0
83
+ description: A gem for checking rzd train tickets
84
+ email:
85
+ - railsr@yahoo.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - lib/rzdtc.rb
98
+ - lib/rzdtc/base.rb
99
+ - lib/rzdtc/version.rb
100
+ - rzdtc.gemspec
101
+ homepage: http://github.com/kirqe/rzdtc
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.5.1
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Rzd tickets checker
125
+ test_files: []