teecket 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/teecket +1 -1
- data/lib/teecket/firefly.rb +29 -15
- data/lib/teecket/page_requester.rb +5 -3
- data/lib/teecket/selectors/firefly.rb +16 -34
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57c92eceaf9a55c6c3a22d20da7be1932df95af0
|
4
|
+
data.tar.gz: f83435a571f2e25883307edeec8217ee64014f58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30574e2b933d4cb8d6739cc4f00c332de083abb94d6afa4c22e9afa31f57bf33877270a37dab1657bc5b042e7f6a4131f3e4e30e3b6f2015b984c244d6174969
|
7
|
+
data.tar.gz: d8be300d172bfecbd602a6c27fb6933b729b4d4175b7b791e9dffcb4234939d7c2b532d79dd75ec57d6701be3a1a098cbbd551e45f11e65bedca3708d72d3335
|
data/bin/teecket
CHANGED
data/lib/teecket/firefly.rb
CHANGED
@@ -21,52 +21,66 @@ class Firefly < Flight
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def get_main_page
|
24
|
-
uri = URI("
|
24
|
+
uri = URI("http://fireflymobile.me-tech.com.my/fylive3/search.php")
|
25
25
|
|
26
26
|
req = Net::HTTP::Get.new(uri.path)
|
27
27
|
|
28
|
-
self.res = request(uri, req)
|
28
|
+
self.res = request(uri, req, false)
|
29
29
|
|
30
30
|
self.cookie = res["Set-Cookie"]
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_search_page
|
34
|
-
uri = URI("
|
34
|
+
uri = URI("http://fireflymobile.me-tech.com.my/fylive3/search.php")
|
35
|
+
|
36
|
+
date_object = Date.strptime(date, "%d-%m-%Y")
|
37
|
+
date_year = date_object.strftime("%Y")
|
38
|
+
date_month = date_object.strftime("%m")
|
39
|
+
date_day = date_object.strftime("%d")
|
35
40
|
|
36
41
|
req = Net::HTTP::Post.new(uri.path, "Cookie" => cookie)
|
37
42
|
req.body = URI.encode_www_form([
|
43
|
+
["action", "search"],
|
38
44
|
["type", 2],
|
39
|
-
["
|
45
|
+
["departing", from],
|
46
|
+
["arriving", to],
|
47
|
+
["d10", date_day],
|
48
|
+
["d11", date_month],
|
49
|
+
["d12", date_year],
|
50
|
+
["departuredate", date],
|
51
|
+
["d20", date_day],
|
52
|
+
["d21", date_month],
|
53
|
+
["d22", date_year],
|
54
|
+
["returndate", date],
|
40
55
|
["adult", 1],
|
41
|
-
["infant", 0]
|
42
|
-
["departure_station", from],
|
43
|
-
["arrival_station", to],
|
44
|
-
["departure_date", date]
|
56
|
+
["infant", 0]
|
45
57
|
])
|
46
58
|
|
47
|
-
self.res = request(uri, req)
|
59
|
+
self.res = request(uri, req, false)
|
48
60
|
end
|
49
61
|
|
50
62
|
def get_result_page
|
51
63
|
if res["location"]
|
52
|
-
uri = URI(res["location"])
|
64
|
+
uri = URI("http://fireflymobile.me-tech.com.my/fylive3/" + res["location"])
|
53
65
|
|
54
66
|
req = Net::HTTP::Get.new(uri.path, "Cookie" => cookie)
|
55
67
|
|
56
|
-
self.res = request(uri, req)
|
68
|
+
self.res = request(uri, req, false)
|
57
69
|
end
|
58
70
|
end
|
59
71
|
|
60
72
|
def process
|
61
73
|
html = Nokogiri::HTML(res.body)
|
62
74
|
|
63
|
-
|
75
|
+
origin, destination = origin_destination_selector(html)
|
76
|
+
|
77
|
+
flights(html).each_with_index do |flight, i|
|
78
|
+
next if i == 0
|
79
|
+
|
64
80
|
depart_at = depart_at_selector(flight)
|
65
81
|
arrive_at = arrive_at_selector(flight)
|
66
82
|
fare = fare_selector(flight)
|
67
83
|
flight_number = flight_number_selector(flight)
|
68
|
-
origin = origin_selector(flight)
|
69
|
-
destination = destination_selector(flight)
|
70
84
|
transit = "NO"
|
71
85
|
|
72
86
|
add_to_fares(flight_name: "Firefly",
|
@@ -81,6 +95,6 @@ class Firefly < Flight
|
|
81
95
|
end
|
82
96
|
|
83
97
|
def flights(data)
|
84
|
-
data.css("
|
98
|
+
data.css("form table:last tr")
|
85
99
|
end
|
86
100
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module PageRequester
|
2
|
-
def request(uri, req)
|
2
|
+
def request(uri, req, use_ssl = true)
|
3
3
|
http = Net::HTTP.new(uri.host, uri.port)
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
if use_ssl
|
6
|
+
http.use_ssl = true
|
7
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
8
|
+
end
|
7
9
|
|
8
10
|
http.request(req)
|
9
11
|
end
|
@@ -2,60 +2,42 @@ module Selectors
|
|
2
2
|
module Firefly
|
3
3
|
def depart_at_selector(flight)
|
4
4
|
value = flight
|
5
|
-
.css("
|
6
|
-
.css("
|
7
|
-
.css("td")[0]
|
5
|
+
.css("td")[1]
|
6
|
+
.css("div")[0]
|
8
7
|
|
9
|
-
|
8
|
+
time_formatter(value)
|
10
9
|
end
|
11
10
|
|
12
11
|
def arrive_at_selector(flight)
|
13
12
|
value = flight
|
14
|
-
.css("div.visible-xs")
|
15
|
-
.css("table")[1]
|
16
13
|
.css("td")[1]
|
14
|
+
.css("div")[1]
|
17
15
|
|
18
|
-
|
16
|
+
time_formatter(value)
|
19
17
|
end
|
20
18
|
|
21
19
|
def fare_selector(flight)
|
22
20
|
value = flight
|
23
|
-
.css("
|
24
|
-
|
25
|
-
|
21
|
+
.css("td")[2]
|
22
|
+
.css("div")[1]
|
23
|
+
.text
|
26
24
|
end
|
27
25
|
|
28
26
|
def flight_number_selector(flight)
|
29
27
|
value = flight
|
30
|
-
.css("
|
31
|
-
.
|
32
|
-
|
33
|
-
flight_number_formatter(value)
|
34
|
-
end
|
35
|
-
|
36
|
-
def origin_selector(flight)
|
37
|
-
flight["onclick"]
|
38
|
-
.scan(/~[A-Z]{3}~/)[0]
|
39
|
-
.gsub("~", "")
|
40
|
-
end
|
41
|
-
|
42
|
-
def destination_selector(flight)
|
43
|
-
flight["onclick"]
|
44
|
-
.scan(/~[A-Z]{3}~/)[1]
|
45
|
-
.gsub("~", "")
|
28
|
+
.css("td")[0]
|
29
|
+
.text
|
46
30
|
end
|
47
31
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
32
|
+
def origin_destination_selector(html)
|
33
|
+
text = html.css('form > div')[1].text
|
34
|
+
text.scan(/[A-Z]{3}/)
|
51
35
|
end
|
52
36
|
|
53
|
-
def fare_formatter(fare)
|
54
|
-
fare.text.strip.gsub(/ MYR/, "")
|
55
|
-
end
|
56
37
|
|
57
|
-
def
|
58
|
-
|
38
|
+
def time_formatter(element)
|
39
|
+
DateTime.strptime(element.text, "%l:%M%p")
|
40
|
+
.strftime("%I:%M %p")
|
59
41
|
end
|
60
42
|
end
|
61
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teecket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amree Zaid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|
@@ -118,3 +118,4 @@ signing_key:
|
|
118
118
|
specification_version: 4
|
119
119
|
summary: Search for flights fare in Malaysia
|
120
120
|
test_files: []
|
121
|
+
has_rdoc:
|