Permalink
Browse files

Updating for new fotolog layout.

  • Loading branch information...
lunks committed Nov 19, 2013
1 parent 1fb0b3f commit a4209e7ef1e3ee78003ca611b0b8bf6eca3ff2b6
Showing with 19 additions and 16 deletions.
  1. +8 −7 app/fotolog.rb
  2. +3 −2 spec/fotolog_spec.rb
  3. +4 −3 spec/main_controller_spec.rb
  4. +4 −4 spec/spec_helper.rb
View
@@ -1,3 +1,4 @@
+require 'net/http'
class Fotolog
attr_accessor :user
@@ -11,30 +12,30 @@ def valid?
end
def year_archive_url year
- "http://www.fotolog.com.br/#{@user}/archive?year=#{year}&month=1"
+ "http://www.fotolog.com.br/#{@user}/archive/1/#{year}"
end
def years
- Nokogiri::HTML(open(archive_url)).css('#years').text.scan(/\d{4}+/)
+ Nokogiri::HTML(open(archive_url)).css('#list_years_calendar').text.scan(/\d{4}+/)
end
def archive_url
- "http://www.fotolog.com/#{@user}/archive"
+ "http://www.fotolog.com.br/#{@user}/archive"
end
def photos
years.map { |year| (1..12).map { |month| photos_for_month year, month}}.flatten
end
def photos_for_month year, month
- doc = Nokogiri::HTML(open("http://www.fotolog.com.br/#{@user}/archive?year=#{year}&month=#{'0' if month.to_i < 10}#{month.to_i}"))
- doc.css('.imageContainer img').map do |photo|
+ doc = Nokogiri::HTML(open("http://www.fotolog.com.br/#{@user}/archive/#{'0' if month.to_i < 10}#{month.to_i}/#{year}"))
+ doc.css('.calendar_month_day img').map do |photo|
full_image_for photo.attributes['src'].value
end
end
def add_to_cache
- cache.set(@user, photos) if cache.get(@user).nil?
+ cache.set(@user, photos) if Array(cache.get(@user)).empty?
add_user_to_cache
end
@@ -50,7 +51,7 @@ def cache
Cache.instance
end
def recent_users
- if cache.get('recent_users').nil?
+ if Array(cache.get('recent_users')).empty?
cache.set 'recent_users', []
end
cache.get 'recent_users'
View
@@ -29,8 +29,9 @@
fotolog.year_archive_url('2004').should == 'http://www.fotolog.com.br/marano/archive?year=2004&month=1'
end
it 'should retrieve all years which have a photo on it' do
+ #TODO: Update to 2014 when time comes. Do not automate.
years = fotolog.years
- years.should == ['2004', '2005', '2006', '2007', '2008', '2009', '2010']
+ years.should == (2003..2013).map(&:to_s)
end
end
@@ -40,7 +41,7 @@
end
it 'should retrieve photo urls' do
- photos = ["http://sp4.fotolog.com.br/photo/20/29/104/marano/1220844280164_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221058240106_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221348619989_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221433699200_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221691789949_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1222477956299_f.jpg"]
+ photos = ["http://sp4.fotolog.com/photo/20/29/104/marano/1220844280164_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221058240106_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221348619989_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221433699200_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221691789949_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1222477956299_f.jpg"]
fotolog.photos_for_month('2008', '09').should == photos
end
it 'should parse photo url correctly' do
@@ -46,9 +46,10 @@ def app
last_response.should be_ok
end
it 'should retrieve a list of photos' do
- photos = ["http://sp4.fotolog.com.br/photo/20/29/104/marano/1220844280164_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221058240106_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221348619989_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221433699200_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1221691789949_f.jpg", "http://sp4.fotolog.com.br/photo/20/29/104/marano/1222477956299_f.jpg"]
-
- photos.each {|photo| last_response.body.match(photo).should be_true }
+ photos = ["http://sp4.fotolog.com/photo/20/29/104/marano/1220844280164_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221058240106_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221348619989_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221433699200_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1221691789949_f.jpg", "http://sp4.fotolog.com/photo/20/29/104/marano/1222477956299_f.jpg"]
+ photos.each do |photo|
+ last_response.body.match(photo).should be_true
+ end
end
end
View
@@ -3,11 +3,11 @@
require 'sinatra'
require 'rack/test'
require 'fakeweb'
-require 'mocha'
+require 'mocha/setup'
set :environment, :test
-require 'support'
+require_relative 'support'
set :views => File.join(File.dirname(__FILE__), "..", "views")
@@ -20,9 +20,9 @@ def fixture_file(file)
def mock_requests_fixture_for_fotolog name
FakeWeb.register_uri(:get, "http://www.fotolog.com/#{name}/archive", :body => fixture_file('archive.html'))
- (2003..2010).to_a.each do |year|
+ (2003..2013).to_a.each do |year|
(1..12).to_a.each do |month|
- FakeWeb.register_uri(:get, "http://www.fotolog.com.br/#{name}/archive?year=#{year}&month=#{'0' if month.to_i < 10}#{month}", :body => fixture_file('photos.html'))
+ FakeWeb.register_uri(:get, "http://www.fotolog.com.br/#{name}/archive/#{'0' if month.to_i < 10}#{month}/#{year}", :body => fixture_file('photos.html'))
end
end

0 comments on commit a4209e7

Please sign in to comment.