Alohaha 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +2 -0
- data/alohaha.gemspec +25 -0
- data/lib/alohaha.rb +29 -0
- data/lib/alohaha/flight.rb +85 -0
- data/lib/alohaha/flight_parse.rb +17 -0
- data/lib/alohaha/settings.rb +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc89a4192840b7f2036d9472b864c5246e40deec
|
4
|
+
data.tar.gz: fb4aa88f2175e5461d240a2e43fd510370531a0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 573f5a695c7ec24343721fce2f03792426713800fd1f54c7c6ac3cbe7defc981be02866c8f49b628580c1a97f10247ce20c9ffcec4eacb89c02f3fc38767b77c
|
7
|
+
data.tar.gz: da79740410984f05b8ffe6e59a6666ce4e5333188f8757e47a6ddfa1686645d534fb85b369baed7a4c91abc13cb5fea6891e74179d8701a170fdc56d36c21875
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 jiunjiun
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#Alohaha
|
2
|
+
|
3
|
+
This API helper get Taoyuan airport flight info
|
4
|
+
|
5
|
+
#Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'alohaha'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install alohaha
|
20
|
+
|
21
|
+
#Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'alohaha'
|
25
|
+
```
|
26
|
+
|
27
|
+
### All flights
|
28
|
+
```
|
29
|
+
haha = Alohaha.new
|
30
|
+
|
31
|
+
haha.flights # All flights
|
32
|
+
```
|
33
|
+
|
34
|
+
###Flight attribute
|
35
|
+
|
36
|
+
```
|
37
|
+
p haha.flights.first
|
38
|
+
```
|
39
|
+
|
40
|
+
```
|
41
|
+
@raw=["2", "A", "CI", "中華航空", "109", "B9", "2015/07/24", "00:05:00", "2015/07/24", "00:15:00", "NRT", "Tokyo", "東京", "已到ARRIVED", "B737-800", "", "", "", "", ""],
|
42
|
+
@terminal="T2",
|
43
|
+
@kind="Arrivals",
|
44
|
+
@code="CI",
|
45
|
+
@code_zh="中華航空",
|
46
|
+
@flight="109",
|
47
|
+
@gate="B9",
|
48
|
+
@datetime=#<DateTime: 2015-07-24T00:05:00+00:00 ((2457228j,300s,0n),+0s,2299161j)>,
|
49
|
+
@expected_datetime=#<DateTime: 2015-07-24T00:15:00+00:00 ((2457228j,900s,0n),+0s,2299161j)>,
|
50
|
+
@destination=#<Destination:0x007febbb3e40a0
|
51
|
+
@iata="NRT",
|
52
|
+
@en="Tokyo",
|
53
|
+
@zh="東京">,
|
54
|
+
@flight_status="已到ARRIVED",
|
55
|
+
@aircraft_type="B737-800",
|
56
|
+
@other_route=#<Destination:0x007febba876cb8
|
57
|
+
@iata="",
|
58
|
+
@en="",
|
59
|
+
@zh="">,
|
60
|
+
@baggage_carousel="",
|
61
|
+
@check_in_counter=""
|
62
|
+
```
|
63
|
+
|
64
|
+
or
|
65
|
+
|
66
|
+
```
|
67
|
+
p haha.flights.first.terminal # "T2"
|
68
|
+
```
|
69
|
+
|
70
|
+
### Arrivals
|
71
|
+
```
|
72
|
+
p haha.arrivals
|
73
|
+
```
|
74
|
+
|
75
|
+
### Departure
|
76
|
+
```
|
77
|
+
p haha.departure
|
78
|
+
```
|
79
|
+
|
80
|
+
#Contributing
|
81
|
+
|
82
|
+
1. Fork it ( https://github.com/jiunjiun/alohaha/fork )
|
83
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
86
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/alohaha.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "alohaha/settings"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "Alohaha"
|
8
|
+
spec.version = Settings::VERSION
|
9
|
+
spec.authors = ["jiunjiun"]
|
10
|
+
spec.email = ["quietmes@gmail.com"]
|
11
|
+
spec.summary = %q{Alohaha}
|
12
|
+
spec.description = %q{This API helper get Taoyuan airport flight info}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency('virtus')
|
25
|
+
end
|
data/lib/alohaha.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'iconv'
|
3
|
+
require 'virtus'
|
4
|
+
|
5
|
+
require "alohaha/settings"
|
6
|
+
require "alohaha/flight"
|
7
|
+
require "alohaha/flight_parse"
|
8
|
+
|
9
|
+
class Alohaha
|
10
|
+
include FlightParse
|
11
|
+
|
12
|
+
def initialize(option = {})
|
13
|
+
source_url(option[:source_url])
|
14
|
+
flights_parse
|
15
|
+
end
|
16
|
+
|
17
|
+
def flights
|
18
|
+
@flights
|
19
|
+
end
|
20
|
+
|
21
|
+
def arrivals
|
22
|
+
@flights.select {|flights| flights.kind == 'Arrivals' }
|
23
|
+
end
|
24
|
+
|
25
|
+
def departure
|
26
|
+
@flights.select {|flights| flights.kind == 'Departure' }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class Destination
|
2
|
+
include Virtus.model
|
3
|
+
|
4
|
+
attribute :iata, String
|
5
|
+
attribute :en, String
|
6
|
+
attribute :zh, String
|
7
|
+
end
|
8
|
+
|
9
|
+
class Flight
|
10
|
+
include Virtus.model
|
11
|
+
|
12
|
+
attribute :terminal, String #1: T1, 2:T2
|
13
|
+
attribute :kind, String #A: Arrivals, D: Departure
|
14
|
+
attribute :code, String
|
15
|
+
attribute :code_zh, String
|
16
|
+
attribute :flight, String
|
17
|
+
attribute :gate, String
|
18
|
+
|
19
|
+
attribute :datetime, DateTime
|
20
|
+
attribute :expected_datetime, DateTime
|
21
|
+
|
22
|
+
attribute :destination, Destination
|
23
|
+
attribute :flight_status, String
|
24
|
+
|
25
|
+
attribute :aircraft_type, String
|
26
|
+
attribute :other_route, Destination
|
27
|
+
attribute :baggage_carousel, String
|
28
|
+
attribute :check_in_counter, String
|
29
|
+
|
30
|
+
attribute :raw, Array
|
31
|
+
|
32
|
+
|
33
|
+
def initialize(raw_data)
|
34
|
+
self.raw = raw_data
|
35
|
+
|
36
|
+
# terminal
|
37
|
+
self.terminal = "T#{raw_data[0]}"
|
38
|
+
|
39
|
+
# kind
|
40
|
+
case raw_data[1]
|
41
|
+
when "A"
|
42
|
+
self.kind = "Arrivals"
|
43
|
+
when "D"
|
44
|
+
self.kind = "Departure"
|
45
|
+
end
|
46
|
+
|
47
|
+
# code
|
48
|
+
self.code = raw_data[2]
|
49
|
+
|
50
|
+
# code
|
51
|
+
self.code_zh = raw_data[3]
|
52
|
+
|
53
|
+
# flight
|
54
|
+
self.flight = raw_data[4]
|
55
|
+
|
56
|
+
# gate
|
57
|
+
self.gate = raw_data[5]
|
58
|
+
|
59
|
+
# datetime
|
60
|
+
self.datetime = "#{raw_data[6]} #{raw_data[7]}"
|
61
|
+
|
62
|
+
# expected_datetime
|
63
|
+
self.expected_datetime = "#{raw_data[8]} #{raw_data[9]}"
|
64
|
+
|
65
|
+
# destination
|
66
|
+
self.destination = Destination.new(iata: raw_data[10], en: raw_data[11], zh: raw_data[12])
|
67
|
+
|
68
|
+
# flight_status
|
69
|
+
self.flight_status = raw_data[13]
|
70
|
+
|
71
|
+
# aircraft_type
|
72
|
+
self.aircraft_type = raw_data[14]
|
73
|
+
|
74
|
+
# other_route
|
75
|
+
self.other_route = Destination.new(iata: raw_data[15], en: raw_data[16], zh: raw_data[17])
|
76
|
+
|
77
|
+
# baggage_carousel
|
78
|
+
self.baggage_carousel = raw_data[18]
|
79
|
+
|
80
|
+
# check_in_counter
|
81
|
+
self.check_in_counter = raw_data[19]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FlightParse
|
2
|
+
# attr_accessor :url, :flights
|
3
|
+
|
4
|
+
def source_url(url = nil)
|
5
|
+
@url = url.nil? || url.length == 0 ? Settings::FLIGHT_URL : url
|
6
|
+
end
|
7
|
+
|
8
|
+
def flights_parse
|
9
|
+
@flights = []
|
10
|
+
|
11
|
+
ic = Iconv.new('UTF-8', 'BIG5')
|
12
|
+
row_data = ic.iconv(open(@url).read)
|
13
|
+
row_data.each_line do |line|
|
14
|
+
@flights << Flight.new(line.split(',').map {|al| al = al.strip})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Alohaha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiunjiun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-25 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: virtus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This API helper get Taoyuan airport flight info
|
56
|
+
email:
|
57
|
+
- quietmes@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- alohaha.gemspec
|
68
|
+
- lib/alohaha.rb
|
69
|
+
- lib/alohaha/flight.rb
|
70
|
+
- lib/alohaha/flight_parse.rb
|
71
|
+
- lib/alohaha/settings.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Alohaha
|
96
|
+
test_files: []
|