Permalink
Browse files

Reindented the entire codebase to the common 2-space layout

  • Loading branch information...
1 parent 4cf450d commit 89fd3506caab5e7265f26b223eb7824bba287110 @markoa markoa committed Dec 6, 2008
View
@@ -15,10 +15,10 @@
set &&= set.fetch
t3 = Time.now
set.each do |photo|
- str =<<EOF
+ str =<<EOF
<a href="#{photo.url}"><img src="#{photo.url('s')}" alt="#{photo.title}"></a>
EOF
- print str.strip+' '
+ print str.strip+' '
end
t4 = Time.now
View
@@ -3,9 +3,9 @@
require 'flickr'
def filename_to_title(filename)
- arr = filename.split(File::SEPARATOR).last.split('.')
- arr.pop
- my_title = arr.join('.')
+ arr = filename.split(File::SEPARATOR).last.split('.')
+ arr.pop
+ my_title = arr.join('.')
end
flickr = Flickr.new('MY_TOKEN')
@@ -24,17 +24,17 @@ def filename_to_title(filename)
pg = 1
nis = []
while (tot > 0)
- nis += flickr.photos.getNotInSet(nil,500,pg)
- pg += 1
- tot -= 500
+ nis += flickr.photos.getNotInSet(nil,500,pg)
+ pg += 1
+ tot -= 500
end
eligible = (set ? set.fetch : []) + nis
to_upload = []
uploaded = []
ARGV.each do |filename|
- my_title = filename_to_title(filename)
- photo = eligible.find{|photo| photo.title==my_title}
- photo ? uploaded << photo : to_upload << filename
+ my_title = filename_to_title(filename)
+ photo = eligible.find{|photo| photo.title==my_title}
+ photo ? uploaded << photo : to_upload << filename
end
##uploaded += to_upload.map do |fname|
@@ -43,38 +43,38 @@ def filename_to_title(filename)
##end
tix = to_upload.map do |fname|
- $stderr.puts "Uploading #{fname}..."
- flickr.photos.upload.upload_file_async(fname)
+ $stderr.puts "Uploading #{fname}..."
+ flickr.photos.upload.upload_file_async(fname)
end
tix = flickr.photos.upload.checkTickets(tix)
while(tix.find_all{|t| t.complete==:incomplete }.length > 0)
- sleep 2
- puts "Checking on the following tickets: "+
- tix.map{|t| "#{t.id} (#{t.complete})"}.join(', ')
- tix = flickr.photos.upload.checkTickets(tix)
+ sleep 2
+ puts "Checking on the following tickets: "+
+ tix.map{|t| "#{t.id} (#{t.complete})"}.join(', ')
+ tix = flickr.photos.upload.checkTickets(tix)
end
failed = tix.find_all{|t| t.complete == :failed}
failed.each { |f| $stderr.puts "Failed to upload #{to_upload[tix.index(f)]}." }
0.upto(tix.length - 1) { |n| puts "#{to_upload[n]}\t#{tix[n].photoid}" }
uploaded += tix.find_all{|t| t.complete == :completed}.map do |ticket|
- flickr.photos.getInfo(ticket.photoid)
+ flickr.photos.getInfo(ticket.photoid)
end
uploaded.each do |photo|
- if set
- set << photo unless set.find{|ph| ph.id == photo.id}
- else
- set = flickr.photosets.create(setname,photo,description)
- end
+ if set
+ set << photo unless set.find{|ph| ph.id == photo.id}
+ else
+ set = flickr.photosets.create(setname,photo,description)
+ end
end
# Refresh the list
set = set.fetch
ARGV.each do |filename|
- my_title = filename_to_title(filename)
- photo = uploaded.find{|ph| ph.title == my_title}
- puts "PIC=#{filename}\t#{photo.id}\t#{photo.url}" if photo
+ my_title = filename_to_title(filename)
+ photo = uploaded.find{|ph| ph.title == my_title}
+ puts "PIC=#{filename}\t#{photo.id}\t#{photo.url}" if photo
end
puts "SET=#{set.url}"
View
@@ -3,63 +3,63 @@
require 'flickr'
class Flickr::Relatedness
- attr_reader :photos
+ attr_reader :photos
- def initialize(photo)
- @photo = photo
- @threads = []
- end
+ def initialize(photo)
+ @photo = photo
+ @threads = []
+ end
- def calc_relatedness
- @threads.each { |th| th.kill }
- @threads = []
- @photos = {}
- walk_tree(0,@photo)
- thread_join
- @photos = @photos.sort{|a,b| b[1]<=>a[1]}.map{|a|
- Flickr::Photo.new(@photo.flickr,a[0]) }
- return self
- end
+ def calc_relatedness
+ @threads.each { |th| th.kill }
+ @threads = []
+ @photos = {}
+ walk_tree(0,@photo)
+ thread_join
+ @photos = @photos.sort{|a,b| b[1]<=>a[1]}.map{|a|
+ Flickr::Photo.new(@photo.flickr,a[0]) }
+ return self
+ end
- def [](i,j=nil)
- return j ? @photos[i,j] : @photos[i]
- end
+ def [](i,j=nil)
+ return j ? @photos[i,j] : @photos[i]
+ end
- private
+ private
- def thread_dead_collect
- threads = @threads.dup
- threads.each { |th| @threads.delete(th) unless th.alive? }
- end
+ def thread_dead_collect
+ threads = @threads.dup
+ threads.each { |th| @threads.delete(th) unless th.alive? }
+ end
- def thread_join(max = 0)
- threads = @threads.dup
- threads.each do |th|
- @threads.delete(th)
- th.join
- break if @threads.length <= max
- end
- end
+ def thread_join(max = 0)
+ threads = @threads.dup
+ threads.each do |th|
+ @threads.delete(th)
+ th.join
+ break if @threads.length <= max
+ end
+ end
- def walk_tree(depth,photo)
- photo.contexts.each do |ctx|
-# thread_join(10) if @threads.length >= 20
- p = proc {
-$stderr.puts "#{ctx.title} (#{ctx.class})"
- set = ctx.fetch
- set.each do |ph|
- walk_tree(depth-1,ph) if depth > 0
- @photos[ph.id] ||= 0
- @photos[ph.id] += 1
- end
- }
- thread_dead_collect
- if @threads.length >= 20
- p.call
- else
- th = Thread.new { p.call }
- @threads << th
- end
- end
- end
+ def walk_tree(depth,photo)
+ photo.contexts.each do |ctx|
+ # thread_join(10) if @threads.length >= 20
+ p = proc {
+ $stderr.puts "#{ctx.title} (#{ctx.class})"
+ set = ctx.fetch
+ set.each do |ph|
+ walk_tree(depth-1,ph) if depth > 0
+ @photos[ph.id] ||= 0
+ @photos[ph.id] += 1
+ end
+ }
+ thread_dead_collect
+ if @threads.length >= 20
+ p.call
+ else
+ th = Thread.new { p.call }
+ @threads << th
+ end
+ end
+ end
end
View
@@ -17,29 +17,29 @@
sethash = {}
allsets.each do |set|
- set = flickr.photosets.getInfo(set)
- photohash = {}
- seturl = "http://www.flickr.com/photos/#{set.owner}/sets/#{set.id}"
- sethash[set.title] = [seturl,photohash]
- flickr.photosets.getPhotos(set).each do |photo|
- phi = PhotoInfo.new
- phi.title = photo.title
- phi.secret = photo.secret
- phi.server = photo.server
- phi.id = photo.id
- photohash[phi.title] = phi
- end
+ set = flickr.photosets.getInfo(set)
+ photohash = {}
+ seturl = "http://www.flickr.com/photos/#{set.owner}/sets/#{set.id}"
+ sethash[set.title] = [seturl,photohash]
+ flickr.photosets.getPhotos(set).each do |photo|
+ phi = PhotoInfo.new
+ phi.title = photo.title
+ phi.secret = photo.secret
+ phi.server = photo.server
+ phi.id = photo.id
+ photohash[phi.title] = phi
+ end
end
photohash = {}
sethash[nil] = photohash
notinsets.each do |photo|
- phi = PhotoInfo.new
- phi.title = photo.title
- phi.secret = photo.secret
- phi.server = photo.server
- phi.id = photo.id
- photohash[phi.title] = phi
+ phi = PhotoInfo.new
+ phi.title = photo.title
+ phi.secret = photo.secret
+ phi.server = photo.server
+ phi.id = photo.id
+ photohash[phi.title] = phi
end
#$stderr.puts sethash.inspect
View
@@ -4,58 +4,57 @@
require 'flickr/token_cache'
class Flickr::Auth < Flickr::APIBase
- attr_accessor :token_cache, :token
-
- def clear_cache
- @token = nil
- @frob = nil
- end
-
- def initialize(flickr, token_cache=nil)
- super(flickr)
- @frob = nil
- @token = nil
- @token_cache = case token_cache
- when String
- Flickr::FileTokenCache.new token_cache
- else
- token_cache
- end
- @token = @token_cache.load_token if @token_cache
- end
-
- def login_link(perms='delete')
- args={ 'api_key' => @flickr.api_key, 'perms' => perms}
- args['frob'] = self.frob
- args['api_sig'] = @flickr.sign(args)
- return "http://flickr.com/services/auth/?"+
- args.to_a.map{|arr| arr.join('=')}.join('&')
- end
-
- def frob=(frob) @frob = frob end
- def frob() return @frob || getFrob end
-
- def getToken(frob=nil)
- frob ||= @frob
- res=@flickr.call_unauth_method('flickr.auth.getToken',
- 'frob'=>frob)
- @token = Flickr::Token.from_xml(res)
- end
-
- def cache_token
- @token_cache.cache_token(@token) if @token_cache
- end
-
- def getFullToken(mini_token)
- res = flickr.call_unauth_method('flickr.auth.getFullToken',
- 'mini_token' => mini_token)
- @token = Flickr::Token.from_xml(res)
- end
-
- def getFrob
- doc = @flickr.call_unauth_method('flickr.auth.getFrob')
- @frob = doc.elements['/frob'].text
- return @frob
- end
+ attr_accessor :token_cache, :token
+
+ def clear_cache
+ @token = nil
+ @frob = nil
+ end
+
+ def initialize(flickr, token_cache=nil)
+ super(flickr)
+ @frob = nil
+ @token = nil
+ @token_cache = case token_cache
+ when String
+ Flickr::FileTokenCache.new token_cache
+ else
+ token_cache
+ end
+ @token = @token_cache.load_token if @token_cache
+ end
+
+ def login_link(perms='delete')
+ args={ 'api_key' => @flickr.api_key, 'perms' => perms}
+ args['frob'] = self.frob
+ args['api_sig'] = @flickr.sign(args)
+ return "http://flickr.com/services/auth/?"+
+ args.to_a.map{|arr| arr.join('=')}.join('&')
+ end
+
+ def frob=(frob) @frob = frob end
+ def frob() return @frob || getFrob end
+
+ def getToken(frob=nil)
+ frob ||= @frob
+ res = @flickr.call_unauth_method('flickr.auth.getToken', 'frob'=>frob)
+ @token = Flickr::Token.from_xml(res)
+ end
+
+ def cache_token
+ @token_cache.cache_token(@token) if @token_cache
+ end
+
+ def getFullToken(mini_token)
+ res = flickr.call_unauth_method('flickr.auth.getFullToken',
+ 'mini_token' => mini_token)
+ @token = Flickr::Token.from_xml(res)
+ end
+
+ def getFrob
+ doc = @flickr.call_unauth_method('flickr.auth.getFrob')
+ @frob = doc.elements['/frob'].text
+ return @frob
+ end
end
Oops, something went wrong.

0 comments on commit 89fd350

Please sign in to comment.