teecket 0.0.10 → 0.0.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c3396f2293552a045170611b47b36723263fe7b
4
- data.tar.gz: 753f68a799c698bce3b52b32a3d3506ff57a9f92
3
+ metadata.gz: 57c92eceaf9a55c6c3a22d20da7be1932df95af0
4
+ data.tar.gz: f83435a571f2e25883307edeec8217ee64014f58
5
5
  SHA512:
6
- metadata.gz: 8f202fad648a31be25acb4fca10b004f6323c5ae2107a27a9717dc00495f7006a61e58101c00df0f2359efc62c304ab947ad8d6f6ee9137d5dae746b400ba7b0
7
- data.tar.gz: cb41d1873292670762b7f70fa7059d0cbeb0167b55311517f3be66b10dd90c5ed2c512df27dc2b73bb6c094e9996d70cb361259f162344e037879a5b1781f761
6
+ metadata.gz: 30574e2b933d4cb8d6739cc4f00c332de083abb94d6afa4c22e9afa31f57bf33877270a37dab1657bc5b042e7f6a4131f3e4e30e3b6f2015b984c244d6174969
7
+ data.tar.gz: d8be300d172bfecbd602a6c27fb6933b729b4d4175b7b791e9dffcb4234939d7c2b532d79dd75ec57d6701be3a1a098cbbd551e45f11e65bedca3708d72d3335
@@ -7,5 +7,5 @@ if ARGV.count == 3
7
7
  output = Teecket.search(from: ARGV[0], to: ARGV[1], date: ARGV[2])
8
8
  puts Printer.table(output)
9
9
  else
10
- puts "Example: teecket KBR KUL 30-07-2015"
10
+ puts "Example: teecket KBR KUL 31-12-2015"
11
11
  end
@@ -21,52 +21,66 @@ class Firefly < Flight
21
21
  end
22
22
 
23
23
  def get_main_page
24
- uri = URI("https://m.fireflyz.com.my/")
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("https://m.fireflyz.com.my/Search")
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
- ["return_date", date],
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
- flights(html).each do |flight|
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("div.market1")
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
- http.use_ssl = true
6
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
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("div.visible-xs")
6
- .css("table")[1]
7
- .css("td")[0]
5
+ .css("td")[1]
6
+ .css("div")[0]
8
7
 
9
- depart_arrive_at_formatter(value)
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
- depart_arrive_at_formatter(value)
16
+ time_formatter(value)
19
17
  end
20
18
 
21
19
  def fare_selector(flight)
22
20
  value = flight
23
- .css("div.visible-xs > div")
24
-
25
- fare_formatter(value)
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("div.visible-xs")
31
- .css("table")[0]
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 depart_arrive_at_formatter(datetime)
49
- datetime = datetime.text.strip.gsub(/\t/, "").match(/^(.*?)(AM|PM)/)[0]
50
- DateTime.parse("#{date} #{datetime}").strftime("%I:%M %p")
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 flight_number_formatter(flight_number)
58
- flight_number.text.strip.gsub(/ /, "").gsub(/FLIGHTNO\./, "")
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.10
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-07-13 00:00:00.000000000 Z
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: