hostelify 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -2,19 +2,12 @@ Manifest
2
2
  README.rdoc
3
3
  Rakefile
4
4
  hostelify.gemspec
5
- lib/hostel.rb
6
- lib/hostel/gomio.rb
7
- lib/hostel/hostel.rb
8
- lib/hostel/hostel_available.rb
9
- lib/hostel/hostelbookers.rb
10
- lib/hostel/hostelworld.rb
11
5
  lib/hostelify.rb
12
6
  lib/hostelify/gomio.rb
13
7
  lib/hostelify/hostel.rb
14
8
  lib/hostelify/hostelbookers.rb
15
9
  lib/hostelify/hostelify.rb
16
10
  lib/hostelify/hostelworld.rb
17
- lib/hostelify/hostelworldmonkey.rb
18
11
  lib/items.rb
19
12
  lib/test.rb
20
13
  spec/_helper.rb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('hostelify', '0.4.3') do |p|
5
+ Echoe.new('hostelify', '0.4.4') do |p|
6
6
  p.description = "Simple Hostel Webscrapper."
7
7
  p.url = "http://github.com/holden/hostelify"
8
8
  p.author = "Holden Thomas"
data/hostelify.gemspec CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{hostelify}
5
- s.version = "0.4.3"
5
+ s.version = "0.4.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Holden Thomas"]
9
- s.date = %q{2010-01-26}
9
+ s.date = %q{2010-05-19}
10
10
  s.description = %q{Simple Hostel Webscrapper.}
11
11
  s.email = %q{holden.thomas@gmail.com}
12
- s.extra_rdoc_files = ["README.rdoc", "lib/hostel.rb", "lib/hostel/gomio.rb", "lib/hostel/hostel.rb", "lib/hostel/hostel_available.rb", "lib/hostel/hostelbookers.rb", "lib/hostel/hostelworld.rb", "lib/hostelify.rb", "lib/hostelify/gomio.rb", "lib/hostelify/hostel.rb", "lib/hostelify/hostelbookers.rb", "lib/hostelify/hostelify.rb", "lib/hostelify/hostelworld.rb", "lib/hostelify/hostelworldmonkey.rb", "lib/items.rb", "lib/test.rb"]
13
- s.files = ["Manifest", "README.rdoc", "Rakefile", "hostelify.gemspec", "lib/hostel.rb", "lib/hostel/gomio.rb", "lib/hostel/hostel.rb", "lib/hostel/hostel_available.rb", "lib/hostel/hostelbookers.rb", "lib/hostel/hostelworld.rb", "lib/hostelify.rb", "lib/hostelify/gomio.rb", "lib/hostelify/hostel.rb", "lib/hostelify/hostelbookers.rb", "lib/hostelify/hostelify.rb", "lib/hostelify/hostelworld.rb", "lib/hostelify/hostelworldmonkey.rb", "lib/items.rb", "lib/test.rb", "spec/_helper.rb", "spec/hb_find_by_hostel.spec", "spec/hb_find_hostels.spec", "spec/helper.rb", "spec/hw_find_by_hostel.spec", "spec/hw_find_hostels.spec"]
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/hostelify.rb", "lib/hostelify/gomio.rb", "lib/hostelify/hostel.rb", "lib/hostelify/hostelbookers.rb", "lib/hostelify/hostelify.rb", "lib/hostelify/hostelworld.rb", "lib/items.rb", "lib/test.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "hostelify.gemspec", "lib/hostelify.rb", "lib/hostelify/gomio.rb", "lib/hostelify/hostel.rb", "lib/hostelify/hostelbookers.rb", "lib/hostelify/hostelify.rb", "lib/hostelify/hostelworld.rb", "lib/items.rb", "lib/test.rb", "spec/_helper.rb", "spec/hb_find_by_hostel.spec", "spec/hb_find_hostels.spec", "spec/helper.rb", "spec/hw_find_by_hostel.spec", "spec/hw_find_hostels.spec"]
14
14
  s.homepage = %q{http://github.com/holden/hostelify}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Hostelify", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{hostelify}
18
- s.rubygems_version = %q{1.3.5}
18
+ s.rubygems_version = %q{1.3.6}
19
19
  s.summary = %q{Simple Hostel Webscrapper.}
20
20
 
21
21
  if s.respond_to? :specification_version then
@@ -1,3 +1,5 @@
1
+ #gave up, gomio sucks
2
+
1
3
  require 'rubygems'
2
4
  require 'mechanize'
3
5
  require 'hpricot'
@@ -1,3 +1,5 @@
1
+ #delete
2
+
1
3
  class Hostelify
2
4
  attr_accessor :hostel_id, :name, :address, :description, :facilities, :ratings, :directions, :geo, :images, :video, :availability
3
5
  attr_accessor :rating, :dorm, :single, :unavailable, :genre
@@ -3,6 +3,8 @@ class Hostelbookers
3
3
  #constants
4
4
  HB_SINGULAR_DETAIL_URL = "http://www.hostelbookers.com/hostels/" #poland/krakow/
5
5
  HB_PLURAL_HOSTELS_URL = "http://www.hostelbookers.com/hostels/" #poland/wroclaw/
6
+ HB_DYNAMIC_URL = "http://www.hostelbookers.com/property/index.cfm?fuseaction=accommodation.search&straccommodationtype=hostels"
7
+ #&intnights=2&intpeople=1&dtearrival=21/05/2010&fromPropertyNameSearch=0&intpropertyid=6281
6
8
 
7
9
  #options
8
10
  @default_options = { :date => date=(Date.today+4).to_s, :no_days => "7", :live => true }
@@ -12,6 +14,7 @@ class Hostelbookers
12
14
  country = options[:location].split(',').last.rstrip.lstrip.gsub(' ','-').squeeze("-")
13
15
 
14
16
  url = HB_PLURAL_HOSTELS_URL + "#{country}/#{city}"
17
+
15
18
 
16
19
  if options[:date]
17
20
  options = @default_options.merge(options)
@@ -44,22 +47,33 @@ class Hostelbookers
44
47
  end
45
48
 
46
49
  def self.find_hostel_by_id(options)
47
- city = options[:location].split(',').first.gsub(' ','')
48
- country = options[:location].split(',').last.gsub(' ','')
50
+ #city = options[:location].split(',').first.gsub(' ','')
51
+ #country = options[:location].split(',').last.gsub(' ','')
49
52
  id = options[:id]
50
- url = HB_SINGULAR_DETAIL_URL + "#{country}/#{city}/#{id}"
53
+
54
+ #url = HB_SINGULAR_DETAIL_URL + "#{country}/#{city}/#{id}"
55
+ url = HB_DYNAMIC_URL + "&intnights=#{options[:no_days]}&fromPropertyNameSearch=0&intpropertyid=#{options[:id]}"
51
56
 
52
57
  hostel = Hostelify.new
53
58
 
54
59
  if options[:date]
55
60
  options = @default_options.merge(options)
56
- data = setSearch_id(url,options[:date],options[:no_days])
57
61
  else
58
- Retryable.try 3 do
59
- data = Hpricot(open(url))
60
- end
62
+ options[:date] = (Date.today+4).to_s
61
63
  end
62
64
 
65
+ date = Date.strptime(options[:date])
66
+ url2 = HB_DYNAMIC_URL + "&intnights=#{options[:no_days]}&intpeople=1&dtearrival=#{date.strftime('%d/%m/%Y')}&fromPropertyNameSearch=0&intpropertyid=6281"
67
+ data = Hpricot(open(url2))
68
+ #data = setSearch_id(url,options[:date],options[:no_days])
69
+ #url2 = HB_DYNAMIC_URL + "&intnights=#{options[:no_days]}&dtearrival=21/05/2010&fromPropertyNameSearch=0&intpropertyid=#{options[:id]}"
70
+
71
+ # else
72
+ # Retryable.try 3 do
73
+ # data = Hpricot(open(url))
74
+ # end
75
+ # end
76
+
63
77
  hostel.hostel_id = id
64
78
  hostel.name = data.at("h1").inner_text
65
79
  hostel.address = data.at("p.address").inner_text
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  describe "with dates to get availabilty and verify output!" do
51
51
  before(:all) do
52
- @h = Hostelbookers.find_hostel_by_id(:location => "krakow,poland", :id => 19831, :date => (Date.today+10).to_s)
52
+ @h = Hostelbookers.find_hostel_by_id(:id => 19831, :date => (Date.today+10).to_s)
53
53
  end
54
54
 
55
55
  it "get first availability and check it merit" do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hostelify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 4
9
+ version: 0.4.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Holden Thomas
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-26 00:00:00 +01:00
17
+ date: 2010-05-19 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -21,19 +26,12 @@ extensions: []
21
26
 
22
27
  extra_rdoc_files:
23
28
  - README.rdoc
24
- - lib/hostel.rb
25
- - lib/hostel/gomio.rb
26
- - lib/hostel/hostel.rb
27
- - lib/hostel/hostel_available.rb
28
- - lib/hostel/hostelbookers.rb
29
- - lib/hostel/hostelworld.rb
30
29
  - lib/hostelify.rb
31
30
  - lib/hostelify/gomio.rb
32
31
  - lib/hostelify/hostel.rb
33
32
  - lib/hostelify/hostelbookers.rb
34
33
  - lib/hostelify/hostelify.rb
35
34
  - lib/hostelify/hostelworld.rb
36
- - lib/hostelify/hostelworldmonkey.rb
37
35
  - lib/items.rb
38
36
  - lib/test.rb
39
37
  files:
@@ -41,19 +39,12 @@ files:
41
39
  - README.rdoc
42
40
  - Rakefile
43
41
  - hostelify.gemspec
44
- - lib/hostel.rb
45
- - lib/hostel/gomio.rb
46
- - lib/hostel/hostel.rb
47
- - lib/hostel/hostel_available.rb
48
- - lib/hostel/hostelbookers.rb
49
- - lib/hostel/hostelworld.rb
50
42
  - lib/hostelify.rb
51
43
  - lib/hostelify/gomio.rb
52
44
  - lib/hostelify/hostel.rb
53
45
  - lib/hostelify/hostelbookers.rb
54
46
  - lib/hostelify/hostelify.rb
55
47
  - lib/hostelify/hostelworld.rb
56
- - lib/hostelify/hostelworldmonkey.rb
57
48
  - lib/items.rb
58
49
  - lib/test.rb
59
50
  - spec/_helper.rb
@@ -80,18 +71,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
71
  requirements:
81
72
  - - ">="
82
73
  - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
83
76
  version: "0"
84
- version:
85
77
  required_rubygems_version: !ruby/object:Gem::Requirement
86
78
  requirements:
87
79
  - - ">="
88
80
  - !ruby/object:Gem::Version
81
+ segments:
82
+ - 1
83
+ - 2
89
84
  version: "1.2"
90
- version:
91
85
  requirements: []
92
86
 
93
87
  rubyforge_project: hostelify
94
- rubygems_version: 1.3.5
88
+ rubygems_version: 1.3.6
95
89
  signing_key:
96
90
  specification_version: 3
97
91
  summary: Simple Hostel Webscrapper.
data/lib/hostel/gomio.rb DELETED
@@ -1,102 +0,0 @@
1
- require 'rubygems'
2
- require 'mechanize'
3
- require 'hpricot'
4
- require 'open-uri'
5
- require 'date'
6
- require 'htmlentities'
7
-
8
- Hpricot.buffer_size = 262144
9
-
10
- class Gomio
11
-
12
- #constants
13
- GOMIO_SINGULAR = "http://www.gomio.com/reservation/chooseBed.aspx?HostelId="
14
- GOMIO_PLURAL_HOSTELS_URL = "http://www.gomio.com/hostels/europe/" #europe/poland/krakow/mama%27s%20hostel/overview.htm
15
-
16
- def self.find_hostel_by_id(options)
17
- #opts = { :directions => false, :images => false, :all => false }.merge options
18
- city = options[:location].split(',').first.gsub(' ','')
19
- country = options[:location].split(',').last.gsub(' ','')
20
- id = options[:id]
21
- url = GOMIO_PLURAL_HOSTELS_URL + "#{country}/#{city}/#{id}/overview.htm"
22
-
23
- #setSearch(url,"2009-09-20",2,7)
24
- data = Hpricot(open(url))
25
-
26
- data = data.search('div[@id="main"]')
27
- name = data.at("h3/span").inner_text.lstrip.rstrip
28
- address = data.at("span.br_address").inner_text.lstrip.rstrip
29
- desc = data.at("div.br_detail").inner_text.lstrip.rstrip
30
- available1 = data.at("td.HasNoAvail_Outer")
31
- available2 = data.at("td.HasNoAvail")
32
- puts "#{available1}, #{available2}"
33
- end
34
-
35
- def self.find_hostels_by_location(options) #location
36
- city = options[:location].split(',').first.gsub(' ','')
37
- country = options[:location].split(',').last.gsub(' ','')
38
-
39
- url = GOMIO_PLURAL_HOSTELS_URL + "#{country}/#{city}/search.htm"
40
-
41
- #data = Hpricot(open(url))
42
- data = setSearch(url,"2009-09-09",2,5)
43
-
44
- data = data.search("div.SearchResultMembers")
45
-
46
- (data/"div.SearchResultsHostel").each do |row|
47
- name = row.at("h3").inner_text.lstrip.rstrip
48
- desc = row.at("p").inner_text.lstrip.rstrip
49
- url = row.at("h3/a")['href']
50
- gomio_id = url.match(/(#{city}).([\d\D]*)(\/overview.htm)/)[2]
51
-
52
- available1 = row/("td.HasNoAvail_Outer/text()").to_a.join(',').split(',')
53
- available2 = row/("td.HasNoAvail_Outer/text()").to_a.join(',').split(',')
54
- available = available1 + available2
55
-
56
- @results = { :gomio_id => gomio_id, :name => name, :unavailable => available }
57
- puts @results
58
- end
59
- return @results
60
- end
61
-
62
- def self.setSearch(url,date,no_ppl,no_days)
63
-
64
- date = Date.strptime(date)
65
- month = date.strftime("%m").to_i
66
- day = date.strftime("%d").to_i
67
- if Time.now.strftime("%y") == date.strftime("%y") then year = 0 else year = 1 end
68
-
69
- agent = WWW::Mechanize.new
70
- page = agent.get(url)
71
-
72
- #the form name
73
- form = page.forms.first # => WWW::Mechanize::Form
74
- #page = agent.submit(form)
75
-
76
- #ctl00_searchbox_sb_ddlMonth
77
- #ctl00_searchbox_sb_ddlDay
78
- #ctl00_searchbox_sb_ddlYear
79
-
80
- #ctl00_searchbox_sb_ddlNights
81
- #ctl00_searchbox_sb_ddlBeds
82
-
83
- form.field_with(:name => 'ctl00$searchbox$sb$ddlMonth').options[month-1].select
84
- form.field_with(:name => 'ctl00$searchbox$sb$ddlDay').options[day-1].select
85
- form.field_with(:name => 'ctl00$searchbox$sb$ddlYear').options[year].select
86
- form.field_with(:name => 'ctl00$searchbox$sb$ddlNights').options[no_days.to_i-1].select
87
- form.field_with(:name => 'ctl00$searchbox$sb$ddlBeds').options[no_ppl.to_i-1].select
88
- #form.field_with(:id => 'Currency').options[4].select #US Currency
89
-
90
- page = agent.submit(form)
91
- data = page.search('//div[@id="main"]')
92
- #puts data
93
- return data
94
- end
95
-
96
- #url = GOMIO_PLURAL_HOSTELS_URL + "poland/krakow/search.htm"
97
-
98
- #Gomio.setSearch(url,"2009-09-20",2,7)
99
- Gomio.find_hostels_by_location(:location => "krakow,poland")
100
- #Gomio.find_hostel_by_id(:id => "mama's%20hostel", :location => "krakow,poland")
101
-
102
- end
data/lib/hostel/hostel.rb DELETED
@@ -1,61 +0,0 @@
1
- class Hostelify
2
- attr_accessor :hostel_id, :name, :address, :description, :facilities, :ratings, :directions, :geo, :images, :video, :availability
3
- attr_accessor :rating, :dorm, :single, :unavailable, :genre
4
-
5
- def initialize(options = {})
6
- options.each {
7
- |k,v|
8
- self.send( "#{k.to_s}=".intern, v)
9
- }
10
- end
11
-
12
- end
13
-
14
- class HostelifyCollection < Array
15
- # This collection does everything an Array does, plus
16
- # you can add utility methods like names.
17
-
18
- def ids
19
- collect do |i|
20
- i.hostel_id
21
- end
22
- end
23
-
24
- def names
25
- collect do |i|
26
- i.name
27
- end
28
- end
29
-
30
- def descs
31
- collect do |i|
32
- i.description
33
- end
34
- end
35
-
36
- end
37
-
38
- class HostelifyAvailable
39
- attr_accessor :name, :price, :spots, :bookdate
40
-
41
- def initialize(name, price, spots, bookdate)
42
- @name = name
43
- @price = price
44
- @spots = spots
45
- @bookdate = bookdate
46
- end
47
-
48
- end
49
-
50
- module Retryable
51
- extend self
52
-
53
- def try times = 1, options = {}, &block
54
- val = yield
55
- rescue options[:on] || Exception
56
- retry if (times -= 1) > 0
57
- else
58
- val
59
- end
60
- end
61
-
@@ -1,11 +0,0 @@
1
- class HostelAvailable
2
- attr_accessor :name, :price, :spots, :bookdate
3
-
4
- def initialize(name, price, spots, bookdate)
5
- @name = name
6
- @price = price
7
- @spots = spots
8
- @bookdate = bookdate
9
- end
10
-
11
- end
@@ -1,180 +0,0 @@
1
- class Hostelbookers
2
-
3
- #constants
4
- HB_SINGULAR_DETAIL_URL = "http://www.hostelbookers.com/hostels/" #poland/krakow/
5
- HB_PLURAL_HOSTELS_URL = "http://www.hostelbookers.com/hostels/" #poland/wroclaw/
6
-
7
- #options
8
- @default_options = { :date => date=(Date.today+4).to_s, :no_days => "7", :live => true }
9
-
10
- def self.find_hostels_by_location(options) #location
11
-
12
- city = options[:location].split(',').first.gsub(' ','')
13
- country = options[:location].split(',').last.gsub(' ','')
14
- url = HB_PLURAL_HOSTELS_URL + "#{country}/#{city}"
15
-
16
- if options[:date]
17
- options = @default_options.merge(options)
18
- date = Date.strptime(options[:date])
19
- data = setSearch(url,options[:date],options[:no_days])
20
- else
21
- Retryable.try 3 do
22
- data = Hpricot(open(url))
23
- end
24
- end
25
-
26
- data = data.search("//div[@id='propertyResultsList']")
27
- #@results = []
28
- @results = HostelifyCollection.new
29
- #coder = HTMLEntities.new
30
- (data/"tr.propertyRow").each do |row|
31
- name = row.at("a.propertyTitle").inner_text
32
- url = row.at("a.propertyTitle")['href']
33
- desc = row.at("p.shortDescription").inner_text
34
- rating = row.at("td.rating/text()")
35
- rating = rating.to_s.to_i unless rating.nil?
36
- dorm = row.at("td.shared/text()")
37
- single = row.at("td.private/text()")
38
- hb_id = url.match(/[\d]{2,5}.$/).to_s.to_i
39
-
40
- #@results << Hostelify.new(:hostel_id => hb_id, :name => name, :description => desc, :rating => rating, :dorm => dorm, :single => single)
41
- @results << Hostelify.new(:hostel_id => hb_id, :name => name, :description => desc, :rating => rating, :dorm => dorm, :single => single)
42
- end
43
- return @results
44
- end
45
-
46
- def self.find_hostel_by_id(options)
47
- city = options[:location].split(',').first.gsub(' ','')
48
- country = options[:location].split(',').last.gsub(' ','')
49
- id = options[:id]
50
- url = HB_SINGULAR_DETAIL_URL + "#{country}/#{city}/#{id}"
51
-
52
- hostel = Hostelify.new
53
-
54
- if options[:date]
55
- options = @default_options.merge(options)
56
- data = setSearch_id(url,options[:date],options[:no_days])
57
- else
58
- Retryable.try 3 do
59
- data = Hpricot(open(url))
60
- end
61
- end
62
-
63
- hostel.hostel_id = id
64
- hostel.name = data.at("h1").inner_text
65
- hostel.address = data.at("p.address").inner_text
66
- hostel.description = data.at('div[@id="overviewPane"]').inner_text
67
- facilities_td = data.at("table.tableFacilities")
68
-
69
- facilities = []
70
- (facilities_td/"td").each do |row|
71
- facilities << row.inner_text
72
- end
73
- hostel.facilities = facilities
74
- extras = []
75
- extras_td = data.at("table.tableFeatures")
76
- (extras_td/"td.name").each do |row|
77
- extras << "Free " + row.inner_text.to_s
78
- end
79
- facilities = facilities + extras
80
-
81
- ratings = []
82
- ratings_td = data.at('div[@id="overviewIndRtng"]/table')
83
-
84
- (ratings_td/"tr").each do |row|
85
- ratings << row.at("td").inner_text.to_s.to_f
86
- end
87
-
88
- hostel.ratings = ratings
89
- images = []
90
- image = data.at('div[@id="propMedia"]/table')
91
- (image/"td").each do |row|
92
- img = row.at("img")['onclick']
93
- if img =~ /(http).*(jpg|gif|png|jpeg)/
94
- images << img.match(/(http).*(jpg|gif|png|jpeg)/)[0]
95
- else
96
- #add youtube?
97
- end
98
- end
99
- hostel.images = images
100
-
101
- if options[:all]
102
- data = Hpricot(open(url + "/map"))
103
- data.search("h2").remove #get rid of header
104
- hostel.directions = data.at('div[@id="directions"]').inner_text
105
- hostel.geo = data.to_s.scan(/-{0,1}\d{1,3}\.\d{7}/).uniq!
106
- end
107
-
108
- if options[:date]
109
- date = Date.strptime(options[:date])
110
- @availables = []
111
- available = data.at("div.tableAvailability/table")
112
- if available
113
- (available/"tr").each do |row|
114
- name = row.at("td.roomType/label/text()")
115
- people = row.at("td.people/select")
116
- people = people.at("option:last-child").inner_text unless people.nil?
117
- price = row.at("td.price")
118
- price = price.inner_text.to_s.match(/[\d.]{1,5}/)[0] unless price.nil?
119
- (0..(options[:no_days].to_i-1)).each do |x|
120
- #@availables << { :name => name, :spots => people, :price => price, :bookdate => (date+x).to_s } unless price.nil?
121
- @availables << HostelifyAvailable.new(name,price,people,(date+x).to_s) unless price.nil?
122
- end
123
- end
124
- end
125
- hostel.availability = @availables
126
- end
127
-
128
- return hostel
129
- end
130
-
131
- def self.setSearch(url,date,no_days)
132
- date = Date.strptime(date).strftime("%d/%m/%Y")
133
- agent = WWW::Mechanize.new
134
- page = agent.get(url)
135
- form = page.form_with(:name => 'searchForm') # => WWW::Mechanize::Form
136
- form.field_with(:name => 'intnights').options[no_days.to_i-1].select
137
- form.dtearrival = date #d/m/y
138
-
139
- Retryable.try 3 do
140
- page = agent.submit(form)
141
- end
142
-
143
- #to dollars!
144
- form = page.forms[0]
145
- form.field_with(:name => 'strSelectedCurrencyCode').options[5].select
146
-
147
- Retryable.try 3 do
148
- page = agent.submit(form)
149
- end
150
-
151
- data = page.search('//div[@id="content"]')
152
-
153
- return data
154
- end
155
-
156
- def self.setSearch_id(url,date,no_days)
157
- date = Date.strptime(date).strftime("%d/%m/%Y")
158
- agent = WWW::Mechanize.new
159
- page = agent.get(url)
160
- form = page.form_with(:name => 'frmCheckAvailBook') # => WWW::Mechanize::Form
161
- form.field_with(:name => 'intNights').options[no_days.to_i-1].select
162
- form.dteArrival = date #d/m/y
163
-
164
- Retryable.try 3 do
165
- page = agent.submit(form)
166
- end
167
- #change currency to dollars
168
- form = page.forms[1]
169
- #puts form.name
170
- form.field_with(:name => 'strSelectedCurrencyCode').options[5].select
171
-
172
- Retryable.try 3 do
173
- page = agent.submit(form)
174
- end
175
- data = page.search('//div[@id="content"]')
176
-
177
- return data
178
- end
179
-
180
- end
@@ -1,205 +0,0 @@
1
- class Hostelworld
2
-
3
- #constants
4
- #location list includes/indexjs.js
5
- HW_SINGULAR_DETAIL_URL = "http://www.hostelworld.com/hosteldetails.php?HostelNumber="
6
- HW_SINGULAR_IMAGE_URL = "http://www.hostelworld.com/hostelpictures.php?HostelNumber="
7
- HW_SINGULAR_AVAILABILITY = "http://www.hostelworld.com/availability.php/"
8
- HW_SINGULAR_YOUTUBE_URL = "http://www.hostelworld.com/youtubevideo.php?HostelNumber="
9
- HW_PLURAL_HOSTELS_URL = "http://www.hostelworld.com/findabed.php/"
10
-
11
- #options
12
- @default_options = { :date => date=(Date.today+4).to_s, :no_days => "7", :no_ppl => "2" }
13
-
14
- def self.parse_html(url)
15
- f = open(url)
16
- f.rewind
17
- Retryable.try 3 do
18
- data = Hpricot(Iconv.conv('utf-8', f.charset, f.readlines.join("\n")))
19
- end
20
- end
21
-
22
- def self.find_hostel_by_id(options)
23
- opts = { :directions => false, :images => false, :all => false }.merge options
24
- id = options[:id].to_s
25
- url = HW_SINGULAR_DETAIL_URL + id
26
-
27
- #coder = HTMLEntities.new
28
- hostel = Hostelify.new
29
- hostel.hostel_id = id
30
-
31
- if options[:date]
32
- options = @default_options.merge(options)
33
- date = Date.strptime(options[:date])
34
- data = setSearch(url, options[:date], options[:no_ppl], options[:no_days])
35
- else
36
- data = parse_html(url)
37
- end
38
-
39
- data = data.search("//div[@id='content']")
40
- data.search("h3").remove #get rid of header
41
-
42
- #title, address, desc, facilities, ratings
43
- hostel.name = data.at("h2").inner_text.gsub(/( in ).*$/,'')
44
- hostel.address = data.at('div[@style="padding-top: 5px"]').inner_text.lstrip
45
-
46
- if options[:date]
47
- hostel.availability = parse_availables(data)
48
- else
49
- hostel.description = data.at('div[@id="microDescription2]').inner_text
50
- end
51
-
52
- #optional
53
- no_photos = data.at('span/a[@id="picLink"]').inner_text.to_i
54
- video = data.at('div[@id="microVideo"]')
55
-
56
- facilities = []
57
- (data/"li.microFacilitiesBoomLi").each do |item|
58
- facilities << item.inner_text
59
- end
60
-
61
- ratings = []
62
- (data/'div[@id="ratingsBar2"]').each do |item|
63
- ratings << item.inner_text.to_i
64
- end
65
-
66
- hostel.facilities = facilities
67
- hostel.ratings = ratings
68
-
69
- if video #exists
70
- data = parse_html(HW_SINGULAR_YOUTUBE_URL + id)
71
- video_url = data.at('param[@name="movie"]')['value']
72
- hostel.video = video_url
73
- #video_url = data.at('tag')
74
- end
75
-
76
- if options[:directions] or options[:all]
77
- data = parse_html(HW_SINGULAR_DETAIL_URL + id + "/directions/")
78
-
79
- #directions, geo
80
- hostel.directions = data.at('div[@id="content"]').inner_text.gsub(/^[\d\D\n]*(DIRECTIONS)/,'')
81
- hostel.geo = data.to_s.scan(/-{0,1}\d{1,3}\.\d{7}/).uniq!
82
- end
83
-
84
- if no_photos and (options[:images] or options[:all])
85
- images = []
86
- (1..no_photos).each do |i|
87
- data = parse_html(HW_SINGULAR_IMAGE_URL + id + '&PicNO=' + i.to_s)
88
- images << (data/"img").first[:src].to_s
89
- end
90
- hostel.images = images
91
- end
92
- hostel # return
93
- end
94
-
95
- def self.find_hostels_by_location(options) #location
96
-
97
- city = options[:location].split(',').first.gsub(' ','')
98
- country = options[:location].split(',').last.gsub(' ','')
99
- url = HW_PLURAL_HOSTELS_URL + "ChosenCity.#{city}/ChosenCountry.#{country}"
100
-
101
- if options[:date]
102
- options = @default_options.merge(options)
103
- date = Date.strptime(options[:date])
104
- data = setSearch(url, options[:date], options[:no_ppl], options[:no_days])
105
- else
106
- data = parse_html(url)
107
- end
108
-
109
- data = data.search("//div[@id='content']")
110
- @results = HostelifyCollection.new
111
-
112
- (data/"div.hostelListing").each do |row|
113
- name = row.at("h3").inner_text
114
- desc = row.at("div.hostelEntry/p").inner_text.to_s.chop.gsub('more info','').squeeze('.')
115
- url = row.at("h3/a")['href']
116
- rating = row.at("h4/text()")
117
- rating = rating.to_s.to_i unless rating.nil?
118
- type = row.at("div.hostelListingImage/span").inner_text
119
- hostel_id = url.match(/[\d]*$/).to_s
120
-
121
- if options[:date]
122
- #price_USD = row.at("span.blueBeds").inner_text #need to fix float
123
- dorm = (row.at("p.hostelListingRate/span.blueBeds/text()")).to_s.gsub(/[A-Z$]*/,'')
124
- single = row.at("p.hostelListingPrivateRate/span.blueBeds/text()").to_s.gsub(/[A-Z$]*/,'')
125
- available = row/"ul.hostelListingDates/li.noAvail/text()"
126
- available = available.to_a.join(',').split(',')
127
- @results << Hostelify.new(:hostel_id => hostel_id, :name => name, :description => desc, :rating => rating, :dorm => dorm, :single => single, :unavailable => available)
128
- else
129
- @results << Hostelify.new(:hostel_id => hostel_id, :name => name, :description => desc, :rating => rating)
130
- end
131
- end
132
- return @results
133
- end
134
-
135
- private
136
-
137
- def self.setSearch(url,date,no_ppl,no_days)
138
-
139
- date = Date.strptime(date)
140
- month = date.strftime("%m").to_i
141
- day = date.strftime("%d").to_i
142
- if Time.now.strftime("%y") == date.strftime("%y") then year = 0 else year = 1 end
143
-
144
- agent = WWW::Mechanize.new
145
- page = agent.get(url)
146
-
147
- #the form name
148
- form = page.forms.first # => WWW::Mechanize::Form
149
-
150
- Retryable.try 3 do
151
- page = agent.submit(form)
152
- end
153
-
154
- #form must be submitted twice because the people writing hostelworld are retards
155
- form = page.forms.first # => WWW::Mechanize::Form
156
- form.field_with(:name => 'selMonth').options[month-1].select
157
- form.field_with(:name => 'selDay').options[day-1].select
158
- form.field_with(:name => 'selYear').options[year].select
159
- form.field_with(:name => 'NumNights').options[no_days.to_i-1].select
160
- form.field_with(:name => 'Persons').options[no_ppl.to_i-1].select
161
- form.field_with(:name => 'Currency').options[4].select #US Currency
162
-
163
- Retryable.try 3 do
164
- page = agent.submit(form)
165
- end
166
-
167
- data = page.search("//div[@id='content']")
168
-
169
- return data
170
- end
171
-
172
- def self.parse_availables(info)
173
-
174
- availability = info.at('table[@id="tableDatesSelected2"]')
175
- availability.search("div").remove
176
-
177
- availables = []
178
-
179
- (availability/"tr").each do |row|
180
- name = (row/"td").first
181
- name = name.inner_text unless name.nil?
182
-
183
- (row/"td").each do |td|
184
- night = td.attributes['title']
185
- if night
186
- price = night.to_s.match(/([\d]{1,3}).([\d]{2})/).to_s
187
- available = night.to_s.match(/(available: )([\d]*)/)
188
- date = night.to_s.match(/(Date: ).*$/).to_s.gsub(/(Date: )|(th)|(nd)|(rd)|(st)/,'')
189
- date = Date.strptime(date, "%a %d %b '%y")
190
-
191
- if available
192
- beds = available.to_s.match(/[\d]{1,2}/)[0]
193
- availables << HostelifyAvailable.new(name,price,beds,date)
194
- else
195
- availables << HostelifyAvailable.new(name,price,0,date)
196
- end
197
- end
198
- end
199
- end
200
- return availables
201
-
202
- end
203
-
204
-
205
- end
data/lib/hostel.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'mechanize'
3
- require 'hpricot'
4
- require 'open-uri'
5
- require 'date'
6
- require 'htmlentities'
7
- require 'iconv'
8
- require 'hostel/hostel'
9
- require 'hostel/hostelworld'
10
- require 'hostel/hostelbookers'
@@ -1,205 +0,0 @@
1
- class Hostelworldmonkey
2
-
3
- #constants
4
- #location list includes/indexjs.js
5
- HW_SINGULAR_DETAIL_URL = "http://www.hostelworld.com/hosteldetails.php?HostelNumber="
6
- HW_SINGULAR_IMAGE_URL = "http://www.hostelworld.com/hostelpictures.php?HostelNumber="
7
- HW_SINGULAR_AVAILABILITY = "http://www.hostelworld.com/availability.php/"
8
- HW_SINGULAR_YOUTUBE_URL = "http://www.hostelworld.com/youtubevideo.php?HostelNumber="
9
- HW_PLURAL_HOSTELS_URL = "http://www.hostelworld.com/findabed.php/"
10
-
11
- #options
12
- @default_options = { :date => date=(Date.today+4).to_s, :no_days => "7", :no_ppl => "2" }
13
-
14
- def self.parse_html(url)
15
- f = open(url)
16
- f.rewind
17
- Retryable.try 3 do
18
- data = Hpricot(Iconv.conv('utf-8', f.charset, f.readlines.join("\n")))
19
- end
20
- end
21
-
22
- def self.find_hostel_by_id(options)
23
- opts = { :directions => false, :images => false, :all => false }.merge options
24
- id = options[:id].to_s
25
- url = HW_SINGULAR_DETAIL_URL + id
26
-
27
- #coder = HTMLEntities.new
28
- hostel = Hostelify.new
29
- hostel.hostel_id = id
30
-
31
- if options[:date]
32
- options = @default_options.merge(options)
33
- date = Date.strptime(options[:date])
34
- data = setSearch(url, options[:date], options[:no_ppl], options[:no_days])
35
- else
36
- data = parse_html(url)
37
- end
38
-
39
- data = data.search("//div[@id='content']")
40
- data.search("h3").remove #get rid of header
41
-
42
- #title, address, desc, facilities, ratings
43
- hostel.name = data.at("h2").inner_text.gsub(/( in ).*$/,'')
44
- hostel.address = data.at('div[@style="padding-top: 5px"]').inner_text.lstrip
45
-
46
- if options[:date]
47
- hostel.availability = parse_availables(data)
48
- else
49
- hostel.description = data.at('div[@id="microDescription2]').inner_text
50
- end
51
-
52
- #optional
53
- no_photos = data.at('span/a[@id="picLink"]').inner_text.to_i
54
- video = data.at('div[@id="microVideo"]')
55
-
56
- facilities = []
57
- (data/"li.microFacilitiesBoomLi").each do |item|
58
- facilities << item.inner_text
59
- end
60
-
61
- ratings = []
62
- (data/'div[@id="ratingsBar2"]').each do |item|
63
- ratings << item.inner_text.to_i
64
- end
65
-
66
- hostel.facilities = facilities
67
- hostel.ratings = ratings
68
-
69
- if video #exists
70
- data = parse_html(HW_SINGULAR_YOUTUBE_URL + id)
71
- video_url = data.at('param[@name="movie"]')['value']
72
- hostel.video = video_url
73
- #video_url = data.at('tag')
74
- end
75
-
76
- if options[:directions] or options[:all]
77
- data = parse_html(HW_SINGULAR_DETAIL_URL + id + "/directions/")
78
-
79
- #directions, geo
80
- hostel.directions = data.at('div[@id="content"]').inner_text.gsub(/^[\d\D\n]*(DIRECTIONS)/,'')
81
- hostel.geo = data.to_s.scan(/-{0,1}\d{1,3}\.\d{7}/).uniq!
82
- end
83
-
84
- if no_photos and (options[:images] or options[:all])
85
- images = []
86
- (1..no_photos).each do |i|
87
- data = parse_html(HW_SINGULAR_IMAGE_URL + id + '&PicNO=' + i.to_s)
88
- images << (data/"img").first[:src].to_s
89
- end
90
- hostel.images = images
91
- end
92
- hostel # return
93
- end
94
-
95
- def self.find_hostels_by_location(options) #location
96
-
97
- city = options[:location].split(',').first.gsub(' ','')
98
- country = options[:location].split(',').last.gsub(' ','')
99
- url = HW_PLURAL_HOSTELS_URL + "ChosenCity.#{city}/ChosenCountry.#{country}"
100
-
101
- if options[:date]
102
- options = @default_options.merge(options)
103
- date = Date.strptime(options[:date])
104
- data = setSearch(url, options[:date], options[:no_ppl], options[:no_days])
105
- else
106
- data = parse_html(url)
107
- end
108
-
109
- data = data.search("//div[@id='content']")
110
- @results = HostelifyCollection.new
111
-
112
- (data/"div.hostelListing").each do |row|
113
- name = row.at("h3").inner_text
114
- desc = row.at("div.hostelEntry/p").inner_text.to_s.chop.gsub('more info','').squeeze('.')
115
- url = row.at("h3/a")['href']
116
- rating = row.at("h4/text()")
117
- rating = rating.to_s.to_i unless rating.nil?
118
- type = row.at("div.hostelListingImage/span").inner_text
119
- hostel_id = url.match(/[\d]*$/).to_s
120
-
121
- if options[:date]
122
- #price_USD = row.at("span.blueBeds").inner_text #need to fix float
123
- dorm = (row.at("p.hostelListingRate/span.blueBeds/text()")).to_s.gsub(/[A-Z$]*/,'')
124
- single = row.at("p.hostelListingPrivateRate/span.blueBeds/text()").to_s.gsub(/[A-Z$]*/,'')
125
- available = row/"ul.hostelListingDates/li.noAvail/text()"
126
- available = available.to_a.join(',').split(',')
127
- @results << Hostelify.new(:hostel_id => hostel_id, :name => name, :description => desc, :rating => rating, :dorm => dorm, :single => single, :unavailable => available)
128
- else
129
- @results << Hostelify.new(:hostel_id => hostel_id, :name => name, :description => desc, :rating => rating)
130
- end
131
- end
132
- return @results
133
- end
134
-
135
- private
136
-
137
- def self.setSearch(url,date,no_ppl,no_days)
138
-
139
- date = Date.strptime(date)
140
- month = date.strftime("%m").to_i
141
- day = date.strftime("%d").to_i
142
- if Time.now.strftime("%y") == date.strftime("%y") then year = 0 else year = 1 end
143
-
144
- agent = WWW::Mechanize.new
145
- page = agent.get(url)
146
-
147
- #the form name
148
- form = page.forms.first # => WWW::Mechanize::Form
149
-
150
- Retryable.try 3 do
151
- page = agent.submit(form)
152
- end
153
-
154
- #form must be submitted twice because the people writing hostelworld are retards
155
- form = page.forms.first # => WWW::Mechanize::Form
156
- form.field_with(:name => 'selMonth').options[month-1].select
157
- form.field_with(:name => 'selDay').options[day-1].select
158
- form.field_with(:name => 'selYear').options[year].select
159
- form.field_with(:name => 'NumNights').options[no_days.to_i-1].select
160
- form.field_with(:name => 'Persons').options[no_ppl.to_i-1].select
161
- form.field_with(:name => 'Currency').options[4].select #US Currency
162
-
163
- Retryable.try 3 do
164
- page = agent.submit(form)
165
- end
166
-
167
- data = page.search("//div[@id='content']")
168
-
169
- return data
170
- end
171
-
172
- def self.parse_availables(info)
173
-
174
- availability = info.at('table[@id="tableDatesSelected2"]')
175
- availability.search("div").remove
176
-
177
- availables = []
178
-
179
- (availability/"tr").each do |row|
180
- name = (row/"td").first
181
- name = name.inner_text unless name.nil?
182
-
183
- (row/"td").each do |td|
184
- night = td.attributes['title']
185
- if night
186
- price = night.to_s.match(/([\d]{1,3}).([\d]{2})/).to_s
187
- available = night.to_s.match(/(available: )([\d]*)/)
188
- date = night.to_s.match(/(Date: ).*$/).to_s.gsub(/(Date: )|(th)|(nd)|(rd)|(st)/,'')
189
- date = Date.strptime(date, "%a %d %b '%y")
190
-
191
- if available
192
- beds = available.to_s.match(/[\d]{1,2}/)[0]
193
- availables << HostelifyAvailable.new(name,price,beds,date)
194
- else
195
- availables << HostelifyAvailable.new(name,price,0,date)
196
- end
197
- end
198
- end
199
- end
200
- return availables
201
-
202
- end
203
-
204
-
205
- end