FlightSearcher 1.0.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.
- data/History.txt +6 -0
- data/Manifest.txt +6 -0
- data/README.txt +45 -0
- data/Rakefile +13 -0
- data/lib/flight_searcher.rb +18 -0
- data/test/test_flight_searcher.rb +164 -0
- metadata +71 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= FlightSearcher
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Screen-scrapes a couple of sites fo Flight prices and availability.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
|
12
|
+
== SYNOPSIS:
|
13
|
+
|
14
|
+
Check Sample.rb
|
15
|
+
|
16
|
+
== REQUIREMENTS:
|
17
|
+
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
|
22
|
+
== LICENSE:
|
23
|
+
|
24
|
+
(The MIT License)
|
25
|
+
|
26
|
+
Copyright (c) 2008 Nitin Bhandari
|
27
|
+
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
29
|
+
a copy of this software and associated documentation files (the
|
30
|
+
'Software'), to deal in the Software without restriction, including
|
31
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
32
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
33
|
+
permit persons to whom the Software is furnished to do so, subject to
|
34
|
+
the following conditions:
|
35
|
+
|
36
|
+
The above copyright notice and this permission notice shall be
|
37
|
+
included in all copies or substantial portions of the Software.
|
38
|
+
|
39
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
40
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
41
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
42
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
43
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
44
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
45
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/flight_searcher.rb'
|
6
|
+
|
7
|
+
Hoe.new('FlightSearcher', Flightsearcher::VERSION) do |p|
|
8
|
+
# p.rubyforge_project = 'uwruby'
|
9
|
+
# p.rubyforge_name = 'FlightSearcherx' # if different than lowercase project name
|
10
|
+
p.developer('Nitin Bhandari', 'nitin.bhandari@gmail.com')
|
11
|
+
end
|
12
|
+
|
13
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,18 @@
|
|
1
|
+
##
|
2
|
+
# Student Name: Nitin Bhandari
|
3
|
+
# Homework Week: Project
|
4
|
+
#
|
5
|
+
|
6
|
+
$: << 'lib'
|
7
|
+
|
8
|
+
require 'indianairlines'
|
9
|
+
require 'jetairways'
|
10
|
+
|
11
|
+
class Flightsearcher
|
12
|
+
VERSION = '1.0.0'
|
13
|
+
|
14
|
+
def sort_flts_by_price flts_ary
|
15
|
+
flts_ary.sort_by { |a| [a.origin, a.price] }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
$: << 'lib'
|
5
|
+
|
6
|
+
require 'flight_searcher'
|
7
|
+
require 'time'
|
8
|
+
|
9
|
+
##
|
10
|
+
# Student Name: Nitin Bhandari
|
11
|
+
# Homework Week: Project
|
12
|
+
#
|
13
|
+
|
14
|
+
class TestFlightSearcher < Test::Unit::TestCase
|
15
|
+
|
16
|
+
def helper_num_month_to_str num
|
17
|
+
Time::RFC2822_MONTH_NAME[num-1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@origin = "MUMBAI"
|
22
|
+
@origin_value = "MUMBAI - BOM"
|
23
|
+
@dest = "DELHI"
|
24
|
+
@dest_value = "DELHI - DEL"
|
25
|
+
|
26
|
+
curr_time = Time.now
|
27
|
+
dep_date_time = curr_time + (30*24*3600)
|
28
|
+
ret_date_time = dep_date_time + (2*24*3600)
|
29
|
+
|
30
|
+
@dep_date = "#{dep_date_time.day}"
|
31
|
+
@dep_mon = helper_num_month_to_str(dep_date_time.mon)
|
32
|
+
@dep_yr = "#{dep_date_time.year}"
|
33
|
+
|
34
|
+
@ret_date = "#{ret_date_time.day}"
|
35
|
+
@ret_mon = helper_num_month_to_str(ret_date_time.mon)
|
36
|
+
@ret_yr = "#{ret_date_time.year}"
|
37
|
+
|
38
|
+
@num_adults = "1"
|
39
|
+
@num_children = "0"
|
40
|
+
@num_infants = "0"
|
41
|
+
|
42
|
+
@journey_type = "R" # Oneway or Return
|
43
|
+
@currency = "INR"
|
44
|
+
|
45
|
+
@qry = Query.new(@origin, @dest, @dep_date, @dep_mon, @dep_yr, @num_adults, @num_children, @num_infants, @journey_type, @ret_date, @ret_mon, @ret_yr, @currency)
|
46
|
+
@agent = WWW::Mechanize.new
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_IndiaAirlines_populate_input_form
|
51
|
+
ia = IndianAirlines.new(@qry)
|
52
|
+
page = ia.fetch_search_page
|
53
|
+
ia.populate_input_form page
|
54
|
+
|
55
|
+
assert_equal @dep_date, ia.input_form.ddate
|
56
|
+
assert_equal "#{@dep_mon} #{@dep_yr}", ia.input_form.dmonthyear
|
57
|
+
assert_equal @ret_date, ia.input_form.rdate
|
58
|
+
assert_equal "#{@ret_mon} #{@ret_yr}", ia.input_form.rmonthyear
|
59
|
+
assert_equal @num_adults, ia.input_form.adults
|
60
|
+
assert_equal @num_children, ia.input_form.children
|
61
|
+
assert_equal @num_infants, ia.input_form.infants
|
62
|
+
assert_equal @origin_value, ia.input_form.Origin
|
63
|
+
assert_equal @dest_value, ia.input_form.Destination
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_IndianAirlines_fetch_flights_One_Way
|
67
|
+
#~ Test one-way flights
|
68
|
+
@qry.journey_type = "O"
|
69
|
+
ia = IndianAirlines.new(@qry)
|
70
|
+
ia.populate_input_form ia.fetch_search_page
|
71
|
+
all_flts = ia.fetch_flights
|
72
|
+
|
73
|
+
assert all_flts.size > 0
|
74
|
+
|
75
|
+
all_flts.each do |flt_info|
|
76
|
+
assert_equal "BOM", flt_info.origin
|
77
|
+
assert_equal "DEL", flt_info.destination
|
78
|
+
assert flt_info.number =~ /IC/ # IC is the airline code and is present in their flight number
|
79
|
+
assert flt_info.price.to_f > 0
|
80
|
+
assert_equal "#{if @qry.dep_date.to_i < 10 then "0" else "" end}#{@qry.dep_date}#{@qry.dep_mon}#{@qry.dep_yr}", flt_info.dep_date
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def helper_JetAirways_create_expected_url
|
86
|
+
expected_url = 'https://secure.jetairways.com/jetobe/onlinebooking.aspx?pricing_type=lowest+available&fare_description=normal&date_flexibility=fixed&date.0=STARTDATE&trip_type=return&date.1=ENDDATE&depart=BOM&dest.1=DEL&persons.0=1&persons.1=0&persons.2=0'
|
87
|
+
|
88
|
+
if(@qry.journey_type == "O") then
|
89
|
+
expected_url.gsub!("trip_type=return", "trip_type=one+way")
|
90
|
+
expected_url.gsub!("&date.1=ENDDATE", "")
|
91
|
+
end
|
92
|
+
expected_url.gsub!("STARTDATE", "#{@dep_date}#{@dep_mon}")
|
93
|
+
expected_url.gsub!("ENDDATE", "#{@ret_date}#{@ret_mon}")
|
94
|
+
expected_url.gsub!("persons.0=1&persons.1=0&persons.2=0", "persons.0=#{@qry.num_adults}&persons.1=#{@qry.num_children}&persons.2=#{@qry.num_infants}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_JetAirways_create_params_url_default
|
98
|
+
ja = JetAirways.new(@qry)
|
99
|
+
expected_url = helper_JetAirways_create_expected_url
|
100
|
+
assert_equal expected_url, ja.create_params_url
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_JetAirways_create_params_url_one_way
|
104
|
+
@qry.journey_type = "O"
|
105
|
+
ja = JetAirways.new(@qry)
|
106
|
+
expected_url = helper_JetAirways_create_expected_url
|
107
|
+
assert_equal expected_url, ja.create_params_url
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_JetAirways_create_params_url_2_children_3_adults
|
111
|
+
@qry.num_adults = 3
|
112
|
+
@qry.num_children = 2
|
113
|
+
ja = JetAirways.new(@qry)
|
114
|
+
expected_url = helper_JetAirways_create_expected_url
|
115
|
+
assert_equal expected_url, ja.create_params_url
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_JetAirways_fetch_flights_One_Way
|
119
|
+
#~ Test one-way flights
|
120
|
+
@qry.journey_type = "O"
|
121
|
+
ja = JetAirways.new(@qry)
|
122
|
+
all_flts = ja.fetch_flights
|
123
|
+
|
124
|
+
assert all_flts.size > 0
|
125
|
+
|
126
|
+
all_flts.each do |flt_info|
|
127
|
+
assert_equal "BOM", flt_info.origin
|
128
|
+
assert_equal "DEL", flt_info.destination
|
129
|
+
assert flt_info.number =~ /9W/ # 9W is the airline code and is present in their flight number
|
130
|
+
assert flt_info.price.to_f > 0
|
131
|
+
assert_equal "#{if @qry.dep_date.to_i < 10 then "0" else "" end}#{@qry.dep_date}#{@qry.dep_mon}#{@qry.dep_yr}", flt_info.dep_date
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_sort_flts_by_price
|
137
|
+
flt1 = FlightInfo.new
|
138
|
+
flt1.origin = "A"
|
139
|
+
flt1.price = 100
|
140
|
+
flt1.destination = "B"
|
141
|
+
|
142
|
+
flt2 = FlightInfo.new
|
143
|
+
flt2.origin = "A"
|
144
|
+
flt2.price = 50
|
145
|
+
|
146
|
+
flt3 = FlightInfo.new
|
147
|
+
flt3.origin = "B"
|
148
|
+
flt3.price = 50
|
149
|
+
|
150
|
+
flt4 = FlightInfo.new
|
151
|
+
flt4.origin = "B"
|
152
|
+
flt4.price = 20
|
153
|
+
|
154
|
+
flt_array = [flt4, flt1] + [flt3, flt2]
|
155
|
+
flt_srchr = Flightsearcher.new
|
156
|
+
sorted_flt_array = flt_srchr.sort_flts_by_price flt_array
|
157
|
+
|
158
|
+
assert_equal flt2, sorted_flt_array[0]
|
159
|
+
assert_equal flt1, sorted_flt_array[1]
|
160
|
+
assert_equal flt4, sorted_flt_array[2]
|
161
|
+
assert_equal flt3, sorted_flt_array[3]
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: FlightSearcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nitin Bhandari
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-22 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.2
|
24
|
+
version:
|
25
|
+
description: Screen-scrapes a couple of sites fo Flight prices and availability.
|
26
|
+
email:
|
27
|
+
- nitin.bhandari@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- lib/flight_searcher.rb
|
42
|
+
- test/test_flight_searcher.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: FIX (url)
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --main
|
48
|
+
- README.txt
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: flightsearcher
|
66
|
+
rubygems_version: 1.3.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: Screen-scrapes a couple of sites fo Flight prices and availability.
|
70
|
+
test_files:
|
71
|
+
- test/test_flight_searcher.rb
|