holden-hostelify 0.2.8 → 0.2.9

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/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('hostelify', '0.2.8') do |p|
5
+ Echoe.new('hostelify', '0.2.9') 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,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{hostelify}
5
- s.version = "0.2.8"
5
+ s.version = "0.2.9"
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{2009-09-10}
9
+ s.date = %q{2009-09-15}
10
10
  s.description = %q{Simple Hostel Webscrapper.}
11
11
  s.email = %q{holden.thomas@gmail.com}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/hostelify.rb", "lib/hostelify/gomio.rb", "lib/hostelify/hostelbookers.rb", "lib/hostelify/hostelify.rb", "lib/hostelify/hostelworld.rb"]
@@ -36,58 +36,62 @@ class Hostelworld
36
36
  data = parse_html(url)
37
37
  end
38
38
 
39
- data = data.search("//div[@id='content']")
40
- data.search("h3").remove #get rid of header
39
+ unless data == "Full"
40
+ data = data.search("//div[@id='content']")
41
+ data.search("h3").remove #get rid of header
41
42
 
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
43
+ #title, address, desc, facilities, ratings
44
+ hostel.name = data.at("h2").inner_text.gsub(/( in ).*$/,'')
45
+ hostel.address = data.at('div[@style="padding-top: 5px"]').inner_text.lstrip
45
46
 
46
- if options[:date]
47
- hostel.availability = parse_availables(data)
48
- else
49
- hostel.description = data.at('div[@id="microDescription2]').inner_text
50
- end
47
+ if options[:date]
48
+ hostel.availability = parse_availables(data)
49
+ else
50
+ hostel.description = data.at('div[@id="microDescription2]').inner_text
51
+ end
51
52
 
52
- #optional
53
- no_photos = data.at('span/a[@id="picLink"]').inner_text.to_i
54
- video = data.at('div[@id="microVideo"]')
53
+ #optional
54
+ no_photos = data.at('span/a[@id="picLink"]').inner_text.to_i
55
+ video = data.at('div[@id="microVideo"]')
55
56
 
56
- facilities = []
57
- (data/"li.microFacilitiesBoomLi").each do |item|
58
- facilities << item.inner_text
59
- end
57
+ facilities = []
58
+ (data/"li.microFacilitiesBoomLi").each do |item|
59
+ facilities << item.inner_text
60
+ end
60
61
 
61
- ratings = []
62
- (data/'div[@id="ratingsBar2"]').each do |item|
63
- ratings << item.inner_text.to_i
64
- end
62
+ ratings = []
63
+ (data/'div[@id="ratingsBar2"]').each do |item|
64
+ ratings << item.inner_text.to_i
65
+ end
65
66
 
66
- hostel.facilities = facilities
67
- hostel.ratings = ratings
67
+ hostel.facilities = facilities
68
+ hostel.ratings = ratings
68
69
 
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
70
+ if video #exists
71
+ data = parse_html(HW_SINGULAR_YOUTUBE_URL + id)
72
+ video_url = data.at('param[@name="movie"]')['value']
73
+ hostel.video = video_url
74
+ #video_url = data.at('tag')
75
+ end
75
76
 
76
- if options[:directions] or options[:all]
77
- data = parse_html(HW_SINGULAR_DETAIL_URL + id + "/directions/")
77
+ if options[:directions] or options[:all]
78
+ data = parse_html(HW_SINGULAR_DETAIL_URL + id + "/directions/")
78
79
 
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
80
+ #directions, geo
81
+ hostel.directions = data.at('div[@id="content"]').inner_text.gsub(/^[\d\D\n]*(DIRECTIONS)/,'')
82
+ hostel.geo = data.to_s.scan(/-{0,1}\d{1,3}\.\d{7}/).uniq!
83
+ end
83
84
 
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
85
+ if no_photos and (options[:images] or options[:all])
86
+ images = []
87
+ (1..no_photos).each do |i|
88
+ data = parse_html(HW_SINGULAR_IMAGE_URL + id + '&PicNO=' + i.to_s)
89
+ images << (data/"img").first[:src].to_s
90
+ end
91
+ hostel.images = images
89
92
  end
90
- hostel.images = images
93
+ else
94
+ hostel = nil
91
95
  end
92
96
  hostel # return
93
97
  end
@@ -147,9 +151,7 @@ class Hostelworld
147
151
  #the form name
148
152
  form = page.forms.first # => WWW::Mechanize::Form
149
153
 
150
- Retryable.try 3 do
151
- page = agent.submit(form)
152
- end
154
+ page = agent.submit(form)
153
155
 
154
156
  #form must be submitted twice because the people writing hostelworld are retards
155
157
  form = page.forms.first # => WWW::Mechanize::Form
@@ -164,8 +166,14 @@ class Hostelworld
164
166
  page = agent.submit(form)
165
167
  end
166
168
 
167
- data = page.search("//div[@id='content']")
169
+ error = page.search("div.microBookingError2")
168
170
 
171
+ if error.to_s.length > 1
172
+ data = "Full"
173
+ else
174
+ data = page.search("//div[@id='content']")
175
+ end
176
+
169
177
  return data
170
178
  end
171
179
 
@@ -13,7 +13,7 @@ describe "should find individual hostel and get object with name etc." do
13
13
 
14
14
  it "address" do
15
15
  @h.address.should match(/^.*(Krakow|Lviv).*$/)
16
- end
16
+ end
17
17
 
18
18
  it "description" do
19
19
  @h.address.should_not be nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holden-hostelify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Holden Thomas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-10 00:00:00 -07:00
12
+ date: 2009-09-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,6 +43,7 @@ files:
43
43
  - spec/hw_find_hostels.spec
44
44
  has_rdoc: true
45
45
  homepage: http://github.com/holden/hostelify
46
+ licenses:
46
47
  post_install_message:
47
48
  rdoc_options:
48
49
  - --line-numbers
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  requirements: []
69
70
 
70
71
  rubyforge_project: hostelify
71
- rubygems_version: 1.2.0
72
+ rubygems_version: 1.3.5
72
73
  signing_key:
73
74
  specification_version: 2
74
75
  summary: Simple Hostel Webscrapper.