rflickr 2006.02.01

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ require 'flickr/base'
2
+
3
+ class Flickr::Urls < Flickr::APIBase
4
+ def getGroup(group)
5
+ group = group.nsid if group.class == Flickr::Group
6
+ res = @flickr.call_method('flickr.urls.getGroup',
7
+ 'group_id' => group)
8
+ return res.elements['/group'].attributes['url']
9
+ end
10
+
11
+ def getUserPhotos(user)
12
+ user = user.nsid if user.respond_to?(:nsid)
13
+ args = {}
14
+ args['user_id'] = user if user
15
+ res = @flickr.call_method('flickr.urls.getUserPhotos',args)
16
+ return res.elements['/user'].attributes['url']
17
+ end
18
+
19
+ def getUserProfile(user)
20
+ user = user.nsid if user.respond_to?(:nsid)
21
+ args = {}
22
+ args['user_id'] = user if user
23
+ res = @flickr.call_method('flickr.urls.getUserProfile',args)
24
+ return res.elements['/user'].attributes['url']
25
+ end
26
+
27
+ def lookupGroup(url)
28
+ res = @flickr.call_method('flickr.urls.lookupGroup','url'=>url)
29
+ els = res.elements
30
+ nsid = els['/group'].attributes['id']
31
+
32
+ g = @flickr.group_cache_lookup(nsid) ||
33
+ Flickr::Group.new(@flickr,nsid,
34
+ els['/group/groupname'].text)
35
+ @flickr.group_cache_store(g)
36
+ return g
37
+ end
38
+
39
+ def lookupUser(url)
40
+ res = @flickr.call_method('flickr.urls.lookupUser','url'=>url)
41
+ els = res.elements
42
+ nsid = els['/user'].attributes['id']
43
+ p = @flickr.person_cache_lookup(nsid) ||
44
+ Flickr::Person.new(@flickr,nsid,
45
+ els['/user/username'].text)
46
+ @flickr.person_cache_store(p)
47
+ return p
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ t0 = Time.now
4
+ require 'flickr'
5
+
6
+ t1 = Time.now
7
+
8
+ flickr = Flickr.new('MY_TOKEN')
9
+
10
+ setname = ARGV.shift
11
+
12
+ sets = flickr.photosets.getList
13
+ t2 = Time.now
14
+ set = sets.find{|s| s.title == setname} # May be nil, we handle that later.
15
+ set &&= set.fetch
16
+ t3 = Time.now
17
+ set.each do |photo|
18
+ str =<<EOF
19
+ <a href="#{photo.url}"><img src="#{photo.url('s')}" alt="#{photo.title}"></a>
20
+ EOF
21
+ print str.strip+' '
22
+ end
23
+ t4 = Time.now
24
+
25
+ puts "\n\n\n"
26
+ puts "Library load: #{t1-t0} seconds"
27
+ puts "photosets.getList: #{t2-t1} seconds"
28
+ puts "Set fetching: #{t3-t2} seconds"
29
+ puts "Formatting: #{t4-t3} seconds"
30
+ puts "TOTAL: #{t4-t0} seconds"
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'flickr'
4
+
5
+ flickr = Flickr.new('MY_TOKEN')
6
+
7
+ sets = flickr.photosets.getList
8
+
9
+ # Get the sets that AREN'T comics and put them at the start.
10
+ flickr.photosets.orderSets(sets.find_all { |set| !(set.title =~ /^Comics /) })
11
+
12
+ # Get the latest comic set and make its photos invisible (I assume
13
+ # that since this runs daily, we only need to do the latest
14
+ # set...otherwise find_all.each would do the trick.
15
+ set = sets.find { |set| set.title =~ /^Comics / }
16
+ set.fetch.each { |p| flickr.photos.setPerms(p,false,false,false,0,0) }
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'flickr'
4
+
5
+ def filename_to_title(filename)
6
+ arr = filename.split(File::SEPARATOR).last.split('.')
7
+ arr.pop
8
+ my_title = arr.join('.')
9
+ end
10
+
11
+ flickr = Flickr.new('MY_TOKEN')
12
+ #flickr.debug = true
13
+
14
+ setname = ARGV.shift
15
+ description = ARGV.shift
16
+
17
+ sets = flickr.photosets.getList
18
+ set = sets.find{|s| s.title == setname} # May be nil, we handle that later.
19
+ set &&= set.fetch
20
+
21
+ # These are photos we may have already uploaded but may or may not have
22
+ # added to this set. A content-based signature would be better. MD5?
23
+ tot = flickr.photos.getNotInSet(nil,1).total
24
+ pg = 1
25
+ nis = []
26
+ while (tot > 0)
27
+ nis += flickr.photos.getNotInSet(nil,500,pg)
28
+ pg += 1
29
+ tot -= 500
30
+ end
31
+ eligible = (set ? set.fetch : []) + nis
32
+ to_upload = []
33
+ uploaded = []
34
+ ARGV.each do |filename|
35
+ my_title = filename_to_title(filename)
36
+ photo = eligible.find{|photo| photo.title==my_title}
37
+ photo ? uploaded << photo : to_upload << filename
38
+ end
39
+
40
+ ##uploaded += to_upload.map do |fname|
41
+ ## $stderr.puts "Uploading #{fname}..."
42
+ ## flickr.photos.getInfo(flickr.photos.upload.upload_file(fname))
43
+ ##end
44
+
45
+ tix = to_upload.map do |fname|
46
+ $stderr.puts "Uploading #{fname}..."
47
+ flickr.photos.upload.upload_file_async(fname)
48
+ end
49
+
50
+ tix = flickr.photos.upload.checkTickets(tix)
51
+ while(tix.find_all{|t| t.complete==:incomplete }.length > 0)
52
+ sleep 2
53
+ puts "Checking on the following tickets: "+
54
+ tix.map{|t| "#{t.id} (#{t.complete})"}.join(', ')
55
+ tix = flickr.photos.upload.checkTickets(tix)
56
+ end
57
+
58
+ failed = tix.find_all{|t| t.complete == :failed}
59
+ failed.each { |f| $stderr.puts "Failed to upload #{to_upload[tix.index(f)]}." }
60
+ 0.upto(tix.length - 1) { |n| puts "#{to_upload[n]}\t#{tix[n].photoid}" }
61
+
62
+ uploaded += tix.find_all{|t| t.complete == :completed}.map do |ticket|
63
+ flickr.photos.getInfo(ticket.photoid)
64
+ end
65
+ uploaded.each do |photo|
66
+ if set
67
+ set << photo unless set.find{|ph| ph.id == photo.id}
68
+ else
69
+ set = flickr.photosets.create(setname,photo,description)
70
+ end
71
+ end
72
+
73
+ # Refresh the list
74
+ set = set.fetch
75
+ ARGV.each do |filename|
76
+ my_title = filename_to_title(filename)
77
+ photo = uploaded.find{|ph| ph.title == my_title}
78
+ puts "PIC=#{filename}\t#{photo.id}\t#{photo.url}" if photo
79
+ end
80
+ puts "SET=#{set.url}"
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'flickr'
4
+
5
+ class Flickr::Relatedness
6
+ attr_reader :photos
7
+
8
+ def initialize(photo)
9
+ @photo = photo
10
+ @threads = []
11
+ end
12
+
13
+ def calc_relatedness
14
+ @threads.each { |th| th.kill }
15
+ @threads = []
16
+ @photos = {}
17
+ walk_tree(0,@photo)
18
+ thread_join
19
+ @photos = @photos.sort{|a,b| b[1]<=>a[1]}.map{|a|
20
+ Flickr::Photo.new(@photo.flickr,a[0]) }
21
+ return self
22
+ end
23
+
24
+ def [](i,j=nil)
25
+ return j ? @photos[i,j] : @photos[i]
26
+ end
27
+
28
+ private
29
+
30
+ def thread_dead_collect
31
+ threads = @threads.dup
32
+ threads.each { |th| @threads.delete(th) unless th.alive? }
33
+ end
34
+
35
+ def thread_join(max = 0)
36
+ threads = @threads.dup
37
+ threads.each do |th|
38
+ @threads.delete(th)
39
+ th.join
40
+ break if @threads.length <= max
41
+ end
42
+ end
43
+
44
+ def walk_tree(depth,photo)
45
+ photo.contexts.each do |ctx|
46
+ # thread_join(10) if @threads.length >= 20
47
+ p = proc {
48
+ $stderr.puts "#{ctx.title} (#{ctx.class})"
49
+ set = ctx.fetch
50
+ set.each do |ph|
51
+ walk_tree(depth-1,ph) if depth > 0
52
+ @photos[ph.id] ||= 0
53
+ @photos[ph.id] += 1
54
+ end
55
+ }
56
+ thread_dead_collect
57
+ if @threads.length >= 20
58
+ p.call
59
+ else
60
+ th = Thread.new { p.call }
61
+ @threads << th
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # Dump a Ruby marshalled file of all photos by set (and not in set)
3
+
4
+ require 'flickr'
5
+
6
+ flickr = Flickr.new('MY_TOKEN')
7
+ allsets = flickr.photosets.getList
8
+
9
+ filename = ARGV.shift or raise Exception.new('Need output filename')
10
+
11
+ # This really won't hack it if you have more than 500, but then you're
12
+ # probably not using this. I am.
13
+ notinsets = flickr.photos.getNotInSet(nil,500)
14
+
15
+ # Stripped down analog of the Flickr::Photo class
16
+ PhotoInfo = Struct.new('PhotoInfo',:title,:id,:secret,:server)
17
+
18
+ sethash = {}
19
+ allsets.each do |set|
20
+ set = flickr.photosets.getInfo(set)
21
+ photohash = {}
22
+ seturl = "http://www.flickr.com/photos/#{set.owner}/sets/#{set.id}"
23
+ sethash[set.title] = [seturl,photohash]
24
+ flickr.photosets.getPhotos(set).each do |photo|
25
+ phi = PhotoInfo.new
26
+ phi.title = photo.title
27
+ phi.secret = photo.secret
28
+ phi.server = photo.server
29
+ phi.id = photo.id
30
+ photohash[phi.title] = phi
31
+ end
32
+ end
33
+
34
+ photohash = {}
35
+ sethash[nil] = photohash
36
+ notinsets.each do |photo|
37
+ phi = PhotoInfo.new
38
+ phi.title = photo.title
39
+ phi.secret = photo.secret
40
+ phi.server = photo.server
41
+ phi.id = photo.id
42
+ photohash[phi.title] = phi
43
+ end
44
+
45
+ #$stderr.puts sethash.inspect
46
+ File.open(filename,'w') { |f| Marshal.dump(sethash,f) }
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: rflickr
5
+ version: !ruby/object:Gem::Version
6
+ version: 2006.02.01
7
+ date: 2006-02-02 00:00:00 -05:00
8
+ summary: Ruby interface to the Flickr API
9
+ require_paths:
10
+ - lib
11
+ email: tschroed@zweknu.org
12
+ homepage: http://rubyforge.org/projects/rflickr/
13
+ rubyforge_project: rflickr
14
+ description: rflickr is a Ruby implementation of the Flickr API. It includes a faithful reproduction of the published API as well as method encapsulation to provide more useful object mappings. rflickr features result caching to improve performance.
15
+ autorequire: rake
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ authors: []
30
+ files:
31
+ - lib/flickr.rb
32
+ - lib/flickr/auth.rb
33
+ - lib/flickr/blogs.rb
34
+ - lib/flickr/contacts.rb
35
+ - lib/flickr/favorites.rb
36
+ - lib/flickr/groups.rb
37
+ - lib/flickr/licenses.rb
38
+ - lib/flickr/notes.rb
39
+ - lib/flickr/people.rb
40
+ - lib/flickr/photos.rb
41
+ - lib/flickr/photosets.rb
42
+ - lib/flickr/pools.rb
43
+ - lib/flickr/reflection.rb
44
+ - lib/flickr/tags.rb
45
+ - lib/flickr/test.rb
46
+ - lib/flickr/transform.rb
47
+ - lib/flickr/upload.rb
48
+ - lib/flickr/urls.rb
49
+ - lib/flickr/base.rb
50
+ - lib/flickr/interestingness.rb
51
+ - sample/album_test.rb
52
+ - sample/comics-reorder.rb
53
+ - sample/loadr.rb
54
+ - sample/relatedness.rb
55
+ - sample/setdumpr.rb
56
+ - GETTING-STARTED
57
+ test_files: []
58
+ rdoc_options: []
59
+ extra_rdoc_files: []
60
+ executables: []
61
+ extensions: []
62
+ requirements: []
63
+ dependencies:
64
+ - !ruby/object:Gem::Dependency
65
+ name: mime-types
66
+ version_requirement:
67
+ version_requirements: !ruby/object:Gem::Version::Requirement
68
+ requirements:
69
+ -
70
+ - ">"
71
+ - !ruby/object:Gem::Version
72
+ version: 0.0.0
73
+ version: