smugmugapi 0.9.6 → 0.9.7

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.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,7 @@
1
+ == 0.9.7 / 2007-12-13
2
+
3
+ * Fixed release manifest
4
+
1
5
  == 0.9.6 / 2007-12-13
2
6
 
3
7
  * Added support in XMLStruct for each_[elem] processing
@@ -2,17 +2,24 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- lib/smugmugapi.rb
5
+ examples/dump_tree.rb
6
+ examples/feed.rb
7
+ examples/gallary_list.rb
8
+ examples/geosync.rb
9
+ examples/login.rb
10
+ examples/smugsftp.rb
11
+ examples/smugsftp/options.rb
12
+ examples/smugurls.rb
13
+ examples/upload.rb
6
14
  lib/smugmug/core.rb
7
15
  lib/smugmug/exception.rb
16
+ lib/smugmug/feed.rb
8
17
  lib/smugmug/logon.rb
9
18
  lib/smugmug/proxy.rb
10
19
  lib/smugmug/upload.rb
11
20
  lib/smugmug/utility.rb
12
21
  lib/smugmug/xmlstruct.rb
13
- examples/upload.rb
14
- test/test_smugmug.rb
15
- test/test_smugmug.rb
22
+ lib/smugmugapi.rb
16
23
  test/test_smugmug.rb
17
24
  test/test_utility.rb
18
25
  test/test_xmlstruct.rb
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+
3
+ require "rubygems"
4
+ require "smugmugapi"
5
+
6
+ # $DEBUG = 1
7
+
8
+ SmugMugAPI.api_version = '1.2.1'
9
+ smugmug.login("hurleyhome", IO.read('password').chomp) do
10
+ # smugmug.login("phurley@gmail.com", IO.read('password').chomp) do
11
+ tree = smugmug.users.get_tree(:heavy => 1)
12
+
13
+ tree.each do |category|
14
+ next if category.empty?
15
+
16
+ puts category.name
17
+ category.albums.each do |album|
18
+ puts " #{album.title}: #{album.image_count}"
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,31 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+
3
+ require "rubygems"
4
+ require "smugmugapi"
5
+
6
+ # $DEBUG = 1
7
+
8
+ SmugMugAPI.api_version = '1.2.1'
9
+ # smugmug.login("phurley@gmail.com", IO.read('password').chomp) do
10
+ smugmug.login("hurleyhome", IO.read('password').chomp) do
11
+
12
+ recent = smugmug.user_feed.nickname
13
+ recent.entries.each do |entry|
14
+ puts entry.title
15
+ puts entry.id
16
+ end
17
+
18
+ end
19
+
20
+ smugmug.global_feed.popular(:all, :image_count => 10).entries.each do |entry|
21
+ puts entry.title
22
+ end
23
+
24
+ smugmug.global_feed.popular(:all, :image_count => 10, :size => :original).entries.each do |entry|
25
+ puts entry.id
26
+ end
27
+
28
+
29
+ __END__
30
+
31
+ smugmug.search.nickname()
@@ -0,0 +1,48 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+
3
+ # $DEBUG = 1
4
+ require "rubygems"
5
+ require "smugmugapi"
6
+
7
+ SmugMugAPI.api_version = '1.2.1'
8
+ smugmug.login("phurley@gmail.com", IO.read('password').chomp) do
9
+
10
+ puts "Logged in"
11
+ albums = smugmug.albums.get(:heavy => true)
12
+
13
+ puts "#{albums.size} albums collected"
14
+ albums.each_album do |album|
15
+ puts "Album Title: #{album.title}"
16
+ locations = []
17
+ lost = []
18
+
19
+ smugmug.images.get(:album_id => album.id).each_image do |image|
20
+ info = smugmug.images.get_info(:image_id => image.id)
21
+ exif = smugmug.images.get_exif(:image_id => image.id)
22
+
23
+ puts "#{image.id}: #{exif.date_time}"
24
+ puts " #{exif.date_time_original}"
25
+ puts " #{exif.date_time_digitized}"
26
+ if info.longitude && info.latitude
27
+ locations << [info.longitude, info.latitude]
28
+ else
29
+ puts "Lost #{info.file_name} at #{info.date}"
30
+ lost << image.id
31
+ end
32
+ end
33
+
34
+ # unless locations.empty?
35
+ # # average the locations, would be better to interpolate, based on time/location
36
+ # # but I am lazy and I don't yet have real
37
+ # longitude = locations.inject(0.0) { |t,v| t + v.first.to_f } / locations.size
38
+ # latitude = locations.inject(0.0) { |t,v| t + v.last.to_f } / locations.size
39
+ # puts longitude
40
+ # puts latitude
41
+ #
42
+ # lost.each do |id|
43
+ # smugmug.images.change_settings(:image_id => id, :longitude => longitude, :latitude => latitude)
44
+ # end
45
+ # end
46
+ end
47
+
48
+ end
@@ -0,0 +1,37 @@
1
+ # $LOAD_PATH.unshift "../lib"
2
+
3
+ # $DEBUG = 1
4
+ require "rubygems"
5
+ require "smugmugapi"
6
+
7
+ SmugMugAPI.api_version = '1.2.1'
8
+ smugmug.login("phurley@gmail.com", IO.read('password').chomp) do
9
+
10
+ albums = smugmug.albums.get(:heavy => true)
11
+
12
+ albums.each_album do |album|
13
+ puts "Album Title: #{album.title}"
14
+ locations = []
15
+ lost = []
16
+
17
+ smugmug.images.get(:album_id => album.id).each_image do |image|
18
+ info = smugmug.images.get_info(:image_id => image.id)
19
+ if info.longitude && info.latitude
20
+ locations << [info.longitude, info.latitude]
21
+ else
22
+ lost << image.id
23
+ end
24
+ end
25
+
26
+ unless locations.empty?
27
+ # average the locations, would be better to interpolate, based on time/location
28
+ longitude = locations.inject(0.0) { |t,v| t + v.first.to_f } / locations.size
29
+ latitude = locations.inject(0.0) { |t,v| t + v.last.to_f } / locations.size
30
+
31
+ lost.each do |id|
32
+ smugmug.images.change_settings(:image_id => id, :longitude => longitude, :latitude => latitude)
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+
3
+ require "rubygems"
4
+ require "smugmugapi"
5
+
6
+ $DEBUG = 1
7
+
8
+ # SmugMugAPI.api_version = '1.2.1'
9
+ smugmug.login("phurley@gmail.com", IO.read('password').chomp) do
10
+ # p SmugMugAPI.cookie
11
+ puts "\n\nLogging\n\n"
12
+ end
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift "../lib"
4
+
5
+ require 'rubygems'
6
+ require 'net/sftp'
7
+ require "smugmugapi"
8
+ require "yaml"
9
+ require "ostruct"
10
+
11
+ require "smugsftp/options"
12
+
13
+ class OpenStruct
14
+ undef id
15
+ end
16
+
17
+ def gather_sftp_metadata(strongie_username, strongie_upload_dir)
18
+ directories = []
19
+ begin
20
+ Net::SFTP.start("#{strongie_username}.strongspace.com", strongie_username) do |sftp|
21
+ handle = sftp.opendir(strongie_upload_dir)
22
+
23
+ sftp.readdir(handle).map do |v|
24
+ # skip the . .. directories
25
+ next if v.filename.match(/^\.{1,2}$/)
26
+
27
+ # only collecting directories (albums) at this level
28
+ next unless v.attributes.permissions[15].zero?
29
+
30
+ dinfo = OpenStruct.new
31
+ dinfo.name = v.filename
32
+ dinfo.images = []
33
+
34
+ directories << dinfo
35
+ end
36
+
37
+ sftp.close_handle(handle)
38
+ end
39
+ rescue Timeout::Error
40
+ puts "Timeout!!!"
41
+ end
42
+ directories
43
+ end
44
+
45
+ def gather_smugmug_metadata
46
+ smuginfo = []
47
+
48
+ # title description category
49
+ smugmug.albums.get(:heavy => 1).each do |album|
50
+ album_info = OpenStruct.new
51
+ album_info.id = album.id
52
+ album_info.category = album.category.name
53
+ album_info.title = album.title
54
+ album_info.description = album.description
55
+ album_info.images = []
56
+
57
+ smugmug.images.get(:album_id => album.id, :heavy => 1).each do |image|
58
+ imginfo = OpenStruct.new
59
+
60
+ # will need video urls when available
61
+ %w(id format caption keywords md5sum, original_url).each do |key|
62
+ imginfo.send("#{key}=", image.method_missing(key))
63
+ end
64
+
65
+ album_info.images << imginfo
66
+ end
67
+ smuginfo << album_info
68
+ end
69
+
70
+ smuginfo
71
+ end
72
+
73
+ def find_missing_albums(smuginfo, sftp)
74
+ dirs = []
75
+ smuginfo.each do |album|
76
+ next if sftp.find { |a| a.name.to_i == album.id.to_i }
77
+ dirs << album
78
+ end
79
+ dirs
80
+ end
81
+
82
+ def create_albums_directories(server, user, dir, missing)
83
+ begin
84
+ Net::SFTP.start("hurleyhome.strongspace.com", "hurleyhome") do |sftp|
85
+
86
+ missing.each do |album|
87
+ name = File.join(dir, album.id + "_" + album.title)
88
+ puts "Creating #{name}"
89
+ sftp.mkdir(name, :permissions => 0644)
90
+ end
91
+
92
+ end
93
+ rescue Timeout::Error
94
+ puts "Timeout!!!"
95
+ end
96
+ end
97
+
98
+ #
99
+ # 1. Gather metadata from smugmug
100
+ # 2. Gather metadata from backup source
101
+ # 3. Create missing album directories in backup
102
+ # 4. Send missing pictures to backup
103
+ # 5. Send smugmug metadata to backup
104
+ #
105
+
106
+ # p parse_options
107
+
108
+ sftp = gather_sftp_metadata("hurleyhome", "smugmug")
109
+ smuginfo = nil
110
+
111
+ smugmug.login("phurley@gmail.com", IO.read('password')) do
112
+ smuginfo = gather_smugmug_metadata
113
+ end
114
+
115
+ missing_albums = find_missing_albums(smuginfo, sftp)
116
+ create_albums_directories("strongspace.com", "hurleyhome", "smugmug", missing_albums)
117
+
118
+ missing_albums.each do |album|
119
+
120
+ end
121
+
122
+ # smugmug_info = gather_smugmug_metadata
123
+
124
+ __END__
125
+
126
+ done = false
127
+ until done
128
+ begin
129
+ Net::SFTP.start("#{strongie_username}.strongspace.com", strongie_username) do |sftp|
130
+ puts "Collect files currently at strongspace"
131
+ handle = sftp.opendir(strongie_upload_dir)
132
+ fids = Hash[*sftp.readdir(handle).map { |v| [v.filename, true] }.flatten]
133
+ sftp.close_handle(handle)
134
+
135
+ f.each_photo do |photo|
136
+ fname = File.basename(photo.url)
137
+ puts "Checking #{fname}"
138
+ next if fids[fname]
139
+
140
+ puts "Reading #{fname}"
141
+ info = photo.read
142
+
143
+ puts "Writing #{fname}"
144
+ sftp.open_handle("flickr/#{fname}", "w") do |io|
145
+ sftp.write(io, info)
146
+ end
147
+
148
+ sleep 3
149
+ end
150
+
151
+ done = true
152
+ end
153
+ rescue Timeout::Error
154
+ puts "Timeout!!!"
155
+ end
156
+ end
@@ -0,0 +1,48 @@
1
+ require "optparse"
2
+
3
+ def parse_options
4
+ options = {
5
+ :user => `whoami`.chomp,
6
+ :server => 'strongspace.com',
7
+ :email => `whoami`.chomp + '@' + `hostname`.chomp
8
+ }
9
+
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = "Usage: smugftp.rb [options]"
12
+
13
+ opts.separator ""
14
+ opts.separator "Specific options:"
15
+
16
+ opts.on("-s", "--server SERVER", "Specify server name") do |server|
17
+ options[:server] = server
18
+ end
19
+
20
+ opts.on("-u", "--user USER", "Specify user name") do |user|
21
+ options[:user] = user
22
+ end
23
+
24
+ opts.on("-a", "--server-pass PASS", "Specify your backup server password") do |pass|
25
+ options[:server_pass] = pass
26
+ end
27
+
28
+ opts.on("-p", "--password PASS", "Specify smugmug password") do |pass|
29
+ options[:password] = pass
30
+ end
31
+
32
+ opts.on("-e", "--email EMAIL", "Specify smugmug email address") do |email|
33
+ options[:email] = email
34
+ end
35
+
36
+ opts.on_tail("-h", "--help", "Show this message") do
37
+ puts opts
38
+ exit
39
+ end
40
+
41
+ opts.on_tail("-v", "--version", "Show version") do
42
+ p OptionParser::Version
43
+ exit
44
+ end
45
+ end.parse!
46
+
47
+ options
48
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require "smugmugapi"
5
+
6
+ smugmug.login("phurley@gmail.com", IO.read('password')) do
7
+
8
+ smugmug.albums.get(:heavy => 1).each do |album|
9
+ # puts album.title
10
+ begin
11
+ smugmug.images.get(:album_id => album.id, :heavy => 1).each do |image|
12
+ next if image.format.match /jpg/i
13
+ puts image
14
+ urls = smugmug.images.getURLs(:image_id => image.id)
15
+ puts urls.original_url
16
+ end
17
+ rescue SmugMugAPI::Error
18
+ $stderr.puts "Error processing"
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,61 @@
1
+ require "uri"
2
+
3
+ class SmugMugAPI
4
+
5
+ def process_feed(method, params)
6
+ args = []
7
+ params << {}
8
+ args << params.shift until params.first.is_a?(Hash)
9
+ params = params.first
10
+
11
+ params[:data] = args.join(" ")
12
+ params[:type] = SmugMugAPI.camelize(method, false)
13
+
14
+ prefix = if @feed == :user_feed
15
+ puts "Processing user feed"
16
+ user = params[:nickname] || SmugMugAPI.nickname
17
+ if method == :userkeyword
18
+ params[:nick_name] = user
19
+ else
20
+ params.delete(:nick_name)
21
+ end
22
+ params[:data] = user if params[:data].empty?
23
+ user
24
+ else
25
+ params.delete(:data) if params[:data].empty?
26
+ "www"
27
+ end
28
+
29
+ params = params.map { |k,v| URI.encode("#{SmugMugAPI.camelize(k)}=#{v}") }.join("&")
30
+
31
+ feed = "http://#{prefix}.smugmug.com/hack/feed.mg?#{params}&format=atom03"
32
+ puts "Process feed #{feed}" if $DEBUG
33
+ SmugMugAPI.get_feed(feed)
34
+ end
35
+
36
+ end
37
+
38
+ __END__
39
+
40
+ url = "http://hurleyhome.smugmug.com/hack/feed.mg?Type=nicknameRecent&Data=hurleyhome&format=atom03"
41
+ uri = URI.parse(url)
42
+
43
+ headers = {}
44
+ headers['User-Agent'] ||= "feed checker 1.0"
45
+
46
+ headers['Cookie'] = SmugMugAPI.cookies.map { |k,v| "#{k}=#{v}"}.join("; ")
47
+
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+
50
+ response = {}
51
+ http.start do
52
+ response = http.get(uri.path + '?' + uri.query, headers)
53
+ end
54
+
55
+ # puts response.body
56
+ body = SmugMugAPI::XMLStruct.new(REXML::Document.new(response.body), true)
57
+
58
+ # body.each("//entry") do |entry|
59
+ # puts entry.title
60
+ # end
61
+ puts body.entries.size
@@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), "smugmug/logon")
7
7
  require File.join(File.dirname(__FILE__), "smugmug/feed")
8
8
 
9
9
  class SmugMugAPI
10
- VERSION = "0.9.6"
10
+ VERSION = "0.9.7"
11
11
 
12
12
  def nickname=(name)
13
13
  SmugMugAPI.nickname = name
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: smugmugapi
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.6
6
+ version: 0.9.7
7
7
  date: 2007-12-13 00:00:00 -05:00
8
8
  summary: A very light wrapper around the SmugMug REST API
9
9
  require_paths:
@@ -55,15 +55,24 @@ files:
55
55
  - Manifest.txt
56
56
  - README.txt
57
57
  - Rakefile
58
- - lib/smugmugapi.rb
58
+ - examples/dump_tree.rb
59
+ - examples/feed.rb
60
+ - examples/gallary_list.rb
61
+ - examples/geosync.rb
62
+ - examples/login.rb
63
+ - examples/smugsftp.rb
64
+ - examples/smugsftp/options.rb
65
+ - examples/smugurls.rb
66
+ - examples/upload.rb
59
67
  - lib/smugmug/core.rb
60
68
  - lib/smugmug/exception.rb
69
+ - lib/smugmug/feed.rb
61
70
  - lib/smugmug/logon.rb
62
71
  - lib/smugmug/proxy.rb
63
72
  - lib/smugmug/upload.rb
64
73
  - lib/smugmug/utility.rb
65
74
  - lib/smugmug/xmlstruct.rb
66
- - examples/upload.rb
75
+ - lib/smugmugapi.rb
67
76
  - test/test_smugmug.rb
68
77
  - test/test_utility.rb
69
78
  - test/test_xmlstruct.rb
metadata.gz.sig CHANGED
Binary file