zvv-cli 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be674d86568ac3a7c933d591c61583b8081c4310
4
+ data.tar.gz: 08d4b193902a1220b3bfb970a77635664f69acd0
5
+ SHA512:
6
+ metadata.gz: 8038f90133cbaf94547edb3d303cdf34b2e2391790aafef94f6fe3563c523d746c5202c2a3291e3ffd31ea3e7bf598bb6b09f1c5f7996a1f5619a064a4e3ad3b
7
+ data.tar.gz: ecdecc997b7484350231cb702eaad2a70bc2851352098aa2a49a3cea194d62de17c4b8c1d67052db886f700c315f91e8bb61aff1a2a86583d871bf412f74a178
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .idea
2
+ .ruby-version
3
+ Gemfile.lock
4
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zvv-cli.gemspec
4
+ gemspec group: :development
5
+
6
+ group :runtime do
7
+ gem 'commander'
8
+ gem 'transprt'
9
+ gem 'colorize'
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 PJK
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,50 @@
1
+ # ZVV CLI -- A saner interface for the Swiss public transport network
2
+
3
+ ## Installation
4
+
5
+ $ gem install zvv-cli
6
+
7
+ ## Usage
8
+
9
+ Get me from Hongg to Thalwil by 13:00
10
+
11
+ ```
12
+ $ zvv c ETH/honggerber thalwil 13@
13
+ Zh, ETH Hönggerberg 11:53 ---> Thalwil 12:38
14
+ Zh, ETH Hönggerberg 11:53 -- B 69 --> Zh, Bucheggplatz 12:01
15
+ Zh, Bucheggplatz 12:04 -- T 11 --> Zh, Bhfquai/HB 12:14
16
+ Walk (00:07:00) to Zh, Bhfquai/HB
17
+ Zh HB 12:21 -- S 24 --> Thalwil 12:38
18
+
19
+ Zh, ETH Hönggerberg 12:04 ---> Thalwil 12:43
20
+ Zh, ETH Hönggerberg 12:04 -- B 37 --> Zh, Zehntenhausplatz 12:09
21
+ Walk (00:04:00) to Zh, Zehntenhausplatz
22
+ Zh Affoltern 12:14 -- S 6 --> Zh HB 12:28
23
+ Zh HB 12:35 -- R 2647 --> Thalwil 12:43
24
+
25
+ Zh, ETH Hönggerberg 12:09 ---> Thalwil 12:53
26
+ Zh, ETH Hönggerberg 12:09 -- B 80 --> Zh Oerlikon, Bhf Nord 12:19
27
+ Walk (00:06:00) to Zh Oerlikon, Bhf Nord
28
+ Zh Oerlikon 12:30 -- S 8 --> Thalwil 12:53
29
+
30
+ Zh, ETH Hönggerberg 12:17 ---> Thalwil 13:00
31
+ Zh, ETH Hönggerberg 12:17 -- B 80 --> Zh Oerlikon, Bhf Nord 12:27
32
+ Walk (00:06:00) to Zh Oerlikon, Bhf Nord
33
+ Zh Oerlikon 12:41 -- S 2 --> Thalwil 13:00
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zvv-cli.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
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/bin/zvv ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ require 'commander'
6
+ require 'transprt'
7
+ require 'colorize'
8
+
9
+ require 'zvv/cli'
10
+ require 'ostruct'
11
+ require 'time'
12
+
13
+ module Patches
14
+ refine String do
15
+ def strftime
16
+ DateTime.iso8601(self).strftime('%H:%M')
17
+ end
18
+
19
+ def subzh
20
+ gsub('Zürich', 'Zh').
21
+ gsub('Bahnhof', 'Bhf')
22
+ end
23
+
24
+ def subcon
25
+ tokens = split(' ')
26
+ tokens[0][-1] + ' ' + tokens[1]
27
+ end
28
+ end
29
+
30
+ refine Hash do
31
+ def to_ostruct
32
+ OpenStruct.new(self).tap do |o|
33
+ each.with_object(o) do |(k,v), o|
34
+ o.send(:"#{k}=", v.to_ostruct) rescue nil
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ refine Array do
41
+ def to_ostruct
42
+ map { |_| _.to_ostruct rescue _ }
43
+ end
44
+ end
45
+ end
46
+
47
+ # TODO
48
+ # autocomplete
49
+ # zone info (if not 110)
50
+
51
+ class App
52
+ using Patches
53
+ include Commander::Methods
54
+
55
+ def run
56
+ program :name, 'ZVV CLI'
57
+ program :description, 'ZVV and Swiss Open Data public transport utility'
58
+ program :version, Zvv::Cli::VERSION
59
+
60
+ command :connection do |c|
61
+ c.syntax = 'from to [departure|@arrival|arrival@]'
62
+ c.description = 'Find connection between two destinations'
63
+ c.action do |args, options|
64
+ time = args[2] || Time.now.to_s
65
+
66
+ isArrivalTime = time.start_with?('@') || time.end_with?('@') ? 1 : 0
67
+ time = time.gsub('@', '')
68
+
69
+ time += ':00' unless time.include? ':'
70
+ time = Time.parse(time)
71
+ time += 24 * 60 ** 2 if time < Time.now # Look up tomorrow's connections
72
+
73
+
74
+ connections = Transprt.connections(
75
+ from: args[0],
76
+ to: args[1],
77
+ date: time.strftime('%Y-%m-%d'),
78
+ time: time.strftime('%H:%M'),
79
+ isArrivalTime: isArrivalTime
80
+ )
81
+
82
+ connections.to_ostruct.each_with_index do |c, i|
83
+ puts ("%s %s ---> %s %s" % [c.from.station.name, c.from.departure.strftime, c.to.station.name, c.to.arrival.strftime]).subzh
84
+ c.sections.each do |s|
85
+ if s.walk
86
+ puts ("Walk (%s) to %s" % [s.walk.duration, s.departure.station.name]).subzh.light_black
87
+ else
88
+ puts ("%s %s -- %s --> %s %s" % [s.departure.station.name, s.departure.departure.strftime, s.journey.name.subcon, s.arrival.station.name, s.arrival.arrival.strftime]).subzh.light_black
89
+ end
90
+ end
91
+ puts unless i == connections.length - 1
92
+ end
93
+ end
94
+ end
95
+
96
+ alias_command :c, :connection
97
+
98
+ run!
99
+ end
100
+ end
101
+
102
+ App.new.run
@@ -0,0 +1,5 @@
1
+ module Zvv
2
+ module Cli
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/zvv/cli.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "zvv/cli/version"
2
+
3
+ if ENV['ZVV_DEBUG']
4
+ require 'byebug'
5
+ require 'pry-byebug'
6
+ end
7
+
8
+ module Zvv
9
+ module Cli
10
+ # Your code goes here...
11
+ end
12
+ end
data/zvv-cli.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zvv/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zvv-cli"
8
+ spec.version = Zvv::Cli::VERSION
9
+ spec.authors = ["PJK"]
10
+ spec.email = ["me@pavelkalvoda.com"]
11
+
12
+ spec.summary = %q{CLI for Swiss public transport network}
13
+ spec.description = %q{CLI for Swiss public transport network}
14
+ spec.homepage = "https://github.com/PJK/zvv-cli"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "byebug"
26
+ spec.add_development_dependency "pry-byebug"
27
+ spec.add_development_dependency "pry-rescue"
28
+
29
+ # TODO fork & update
30
+ spec.add_dependency "commander"
31
+ spec.add_dependency "transprt"
32
+ spec.add_dependency "colorize"
33
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zvv-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - PJK
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-20 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-rescue
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: commander
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: transprt
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: colorize
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: CLI for Swiss public transport network
140
+ email:
141
+ - me@pavelkalvoda.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - bin/setup
154
+ - bin/zvv
155
+ - lib/zvv/cli.rb
156
+ - lib/zvv/cli/version.rb
157
+ - zvv-cli.gemspec
158
+ homepage: https://github.com/PJK/zvv-cli
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.5.1
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: CLI for Swiss public transport network
182
+ test_files: []