flickr_sync 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/HISTORY.rdoc +9 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +10 -0
- data/bin/flickr_sync +5 -0
- data/lib/flickr_sync.rb +6 -0
- data/lib/flickr_sync/cli.rb +75 -0
- data/lib/flickr_sync/preferences.rb +31 -0
- data/lib/flickr_sync/prompt.rb +19 -0
- data/spec/flickr_sync/prompt_spec.rb +39 -0
- data/spec/spec_helper.rb +6 -0
- metadata +136 -0
data/.gemtest
ADDED
File without changes
|
data/HISTORY.rdoc
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Mark Ryall
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= flickr sync
|
2
|
+
|
3
|
+
This is a command line utility to synchronise a folder containing images with flickr.
|
4
|
+
|
5
|
+
= Usage
|
6
|
+
|
7
|
+
Here you sit expectantly in front of a computer at the command line.
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
gem install flickr_synch_
|
12
|
+
|
13
|
+
== Launch
|
14
|
+
|
15
|
+
flickr_sync --help
|
16
|
+
|
17
|
+
By default, this will check whether a photo with the same title already exists. If you specify the --optimistic flag, the duplicate check will be skipped.
|
18
|
+
|
19
|
+
All photos will be uploaded with visibility limited to family and titles will be the same as the file name.
|
20
|
+
|
21
|
+
The past uploads will be stored in a file called written.txt and any duplicates (ie. more than one copy of the same image found on flickr) will be stored in a file called duplicates.txt.
|
22
|
+
|
23
|
+
= Future plans for world domination
|
24
|
+
|
25
|
+
* Perhaps use absolute paths for file names
|
26
|
+
* Replace hideous find command with a path iterator
|
27
|
+
* Handle videos
|
data/Rakefile
ADDED
data/bin/flickr_sync
ADDED
data/lib/flickr_sync.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'clamp'
|
2
|
+
require 'fleakr'
|
3
|
+
require 'pathname'
|
4
|
+
require 'splat'
|
5
|
+
|
6
|
+
module FlickrSync
|
7
|
+
class Cli < Clamp::Command
|
8
|
+
option "--optimistic", :flag, "assume there are no duplicates"
|
9
|
+
parameter "DIRECTORY_PATH", "the folder containing images"
|
10
|
+
|
11
|
+
def execute
|
12
|
+
preferences = FlickrSync::Preferences.new
|
13
|
+
prompt = FlickrSync::Prompt.new STDIN, STDOUT
|
14
|
+
|
15
|
+
preferences[:api_key] ||= prompt.answer 'What is your Flickr API key'
|
16
|
+
preferences[:shared_secret] ||= prompt.answer 'What is your Flickr Shared Secret'
|
17
|
+
preferences[:auth_token] ||= prompt.answer 'What is your Flickr Auth'
|
18
|
+
preferences[:username] ||= prompt.answer 'What is your Flickr username'
|
19
|
+
|
20
|
+
Fleakr.api_key = preferences[:api_key]
|
21
|
+
Fleakr.shared_secret = preferences[:shared_secret]
|
22
|
+
Fleakr.auth_token = preferences[:auth_token]
|
23
|
+
user = Fleakr.user preferences[:username]
|
24
|
+
|
25
|
+
written_path = File.join directory_path, 'written.txt'
|
26
|
+
duplicates_path = File.join directory_path, 'duplicates.txt'
|
27
|
+
|
28
|
+
allfiles = `find #{directory_path}/*`.split("\n").select {|p| ['.jpg', '.gif'].include? File.extname(p).downcase}
|
29
|
+
puts "Found #{allfiles.count} image files"
|
30
|
+
writtenfiles = load_list written_path
|
31
|
+
puts "Found #{writtenfiles.count} previously sent files"
|
32
|
+
newfiles = allfiles - writtenfiles
|
33
|
+
puts "Found #{newfiles.count} files to send"
|
34
|
+
|
35
|
+
newfiles.each_with_index do |file, index|
|
36
|
+
path = Pathname.new file
|
37
|
+
puts "#{path} (#{index+1}/#{newfiles.count})"
|
38
|
+
unless optimistic?
|
39
|
+
results = Fleakr.search :user_id => user.id, :text => path.basename.to_s.split('.').first
|
40
|
+
skip_upload = false
|
41
|
+
unless results.empty?
|
42
|
+
ids = results.map {|r| r.id }.join ','
|
43
|
+
puts "Found #{results.size} results on flickr: #{ids}"
|
44
|
+
results.each {|r| r.small.url.to_launcher }
|
45
|
+
file.to_launcher
|
46
|
+
if prompt.ask('Had the photo already been uploaded', true)
|
47
|
+
skip_upload = true
|
48
|
+
if results.size > 1
|
49
|
+
File.open(duplicates_path, 'a') {|f| f.puts "#{file},#{ids}"} if prompt.ask('Are these all duplicates', true)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
if skip_upload
|
55
|
+
puts "skipping upload"
|
56
|
+
else
|
57
|
+
puts "uploading photo"
|
58
|
+
Fleakr.upload file, :viewable_by => :family, :hide? => true
|
59
|
+
end
|
60
|
+
File.open(written_path, 'a') {|f| f.puts file }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
private
|
64
|
+
def load_list path
|
65
|
+
return [] unless File.exist? path
|
66
|
+
lines = []
|
67
|
+
File.open path do |file|
|
68
|
+
while line = file.gets
|
69
|
+
lines << line.chomp
|
70
|
+
end
|
71
|
+
end
|
72
|
+
lines
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module FlickrSync
|
4
|
+
class Preferences
|
5
|
+
def initialize
|
6
|
+
@preference_path = home_path '.flickr_sync'
|
7
|
+
if File.exists? @preference_path
|
8
|
+
@preferences = YAML.load File.read(@preference_path)
|
9
|
+
else
|
10
|
+
@preferences = {}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def [] key
|
15
|
+
@preferences[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
def []= key, value
|
19
|
+
@preferences[key] = value
|
20
|
+
persist
|
21
|
+
end
|
22
|
+
private
|
23
|
+
def home_path *paths
|
24
|
+
File.join File.expand_path('~'), *paths
|
25
|
+
end
|
26
|
+
|
27
|
+
def persist
|
28
|
+
File.open(@preference_path, 'w') {|f| f.puts @preferences.to_yaml}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FlickrSync
|
2
|
+
class Prompt
|
3
|
+
def initialize inio, outio
|
4
|
+
@inio, @outio = inio, outio
|
5
|
+
end
|
6
|
+
|
7
|
+
def ask prompt, default
|
8
|
+
default_answer = default ? 'y' : 'n'
|
9
|
+
response = answer prompt, default_answer
|
10
|
+
response = default_answer if response.empty?
|
11
|
+
response.start_with? 'y'
|
12
|
+
end
|
13
|
+
|
14
|
+
def answer prompt, default=nil
|
15
|
+
@outio.print default ? "#{prompt} [#{default}] ? " : "#{prompt} ? "
|
16
|
+
@inio.gets.chomp.strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path '../../spec_helper.rb', __FILE__
|
2
|
+
|
3
|
+
describe FlickrSync::Prompt do
|
4
|
+
before do
|
5
|
+
@inio = stub 'inio', :gets => ''
|
6
|
+
@outio = stub 'outio', :print => nil
|
7
|
+
@prompt = FlickrSync::Prompt.new @inio, @outio
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#ask' do
|
11
|
+
it 'should write prompt with true default' do
|
12
|
+
@outio.should_receive(:print).with 'Is this it [y] ? '
|
13
|
+
@prompt.ask 'Is this it', true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should write prompt with false default' do
|
17
|
+
@outio.should_receive(:print).with 'Is this it [n] ? '
|
18
|
+
@prompt.ask 'Is this it', false
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return true when true is default and nothing is entered' do
|
22
|
+
@prompt.ask('anything', true).should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return false when false is default and nothing is entered' do
|
26
|
+
@prompt.ask('anything', false).should be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return false when true is default and n is entered' do
|
30
|
+
@inio.should_receive(:gets).and_return 'n'
|
31
|
+
@prompt.ask('anything', true).should be_false
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return true when false is default and y is entered' do
|
35
|
+
@inio.should_receive(:gets).and_return 'y'
|
36
|
+
@prompt.ask('anything', true).should be_true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flickr_sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Ryall
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-05 00:00:00 +10:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: clamp
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fleakr
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: splat
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0.8"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: gemesis
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "2"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
description: |
|
83
|
+
Flickr is a very effective way to backup lots of images but the upload tools are all pretty awful.
|
84
|
+
|
85
|
+
Hopefully this is marginally less painful
|
86
|
+
|
87
|
+
email: mark@ryall.name
|
88
|
+
executables:
|
89
|
+
- flickr_sync
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
extra_rdoc_files: []
|
93
|
+
|
94
|
+
files:
|
95
|
+
- lib/flickr_sync/cli.rb
|
96
|
+
- lib/flickr_sync/preferences.rb
|
97
|
+
- lib/flickr_sync/prompt.rb
|
98
|
+
- lib/flickr_sync.rb
|
99
|
+
- spec/flickr_sync/prompt_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- bin/flickr_sync
|
102
|
+
- README.rdoc
|
103
|
+
- MIT-LICENSE
|
104
|
+
- HISTORY.rdoc
|
105
|
+
- Rakefile
|
106
|
+
- .gemtest
|
107
|
+
has_rdoc: true
|
108
|
+
homepage: http://github.com/markryall/flickr_sync
|
109
|
+
licenses: []
|
110
|
+
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: "0"
|
128
|
+
requirements: []
|
129
|
+
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.5.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: command line utility to synch a folder with flickr
|
135
|
+
test_files: []
|
136
|
+
|