flickpaper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -5
- data/flickpaper.gemspec +2 -2
- data/lib/flickpaper.rb +113 -46
- data/version +1 -1
- metadata +4 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8416847871609b13d927e4e9cb892a7b62548697
|
4
|
+
data.tar.gz: a3aa388f991e63ffb78ca98f881d8ac6d957ee44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71075de7292559348356e1cb344f6b7bef71884c308e94ace4cb411f7ae3587963c6022645ac96387e05b6542ccc1c67eb4698f9a108736af14b5423e0cfec39
|
7
|
+
data.tar.gz: 78ed6977afe25984ceeb06b55636533142deb2df4b7bf2dde1b6ac7b34c4d4d2e055fc7b1459ab431dbc27954378dbd7b4cc721087a42c34b3e11005217446cb
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Flickpaper
|
2
2
|
|
3
|
-
A [Flickr App](https://www.flickr.com/services/apps/72157658406991003)
|
3
|
+
A [Ruby Gem](https://rubygems.org/gems/flickpaper) and [Flickr App](https://www.flickr.com/services/apps/72157658406991003)
|
4
|
+
that sets your GNOME or OSX wallpaper to a recent interesting photo.
|
5
|
+
|
6
|
+
Does not (and will likely never) work under MS Windows.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -26,14 +29,35 @@ $ bundle
|
|
26
29
|
|
27
30
|
```shell
|
28
31
|
Usage: $ flickpaper [options]
|
29
|
-
-d, --dump
|
30
|
-
-i, --image
|
31
|
-
-
|
32
|
-
|
32
|
+
-d, --dump PATH Dump file for used photo ids. Default: $HOME/.flickpaper.dump
|
33
|
+
-i, --image PATH Where to store the downloaded image. Default: $HOME/.flickpaper.jpg
|
34
|
+
-l, --log PATH Path to log file. Default: STDOUT
|
35
|
+
-p, --per-page PER_PAGE Number of interesting photos per page in flickr api call. Default: 100
|
36
|
+
--date DATE A specific date, formatted as YYYY-MM-DD, to return interesting photos for. Default: null (most recent)
|
37
|
+
--page PAGE The page of results to return. Default: 1
|
38
|
+
-s, --size SIZE Minimum acceptable image size. Default: Large 2048
|
39
|
+
-v, --verbose Be verbose.
|
40
|
+
--sizes Print sizes and exit.
|
41
|
+
--version Show version and exit.
|
33
42
|
```
|
34
43
|
|
35
44
|
Use with cron to periodically get a new interesting desktop wallpaper.
|
36
45
|
|
46
|
+
Most of the time you are using a ruby switcher (rvm, rbenv, chruby, etc), which means
|
47
|
+
you will want a way to call the correct gem executable via cron. A script similar to this will
|
48
|
+
work for chruby. You would need to adapt it for your ruby switcher and ruby version.
|
49
|
+
|
50
|
+
```shell
|
51
|
+
#!/bin/bash
|
52
|
+
|
53
|
+
source /usr/local/share/chruby/chruby.sh
|
54
|
+
chruby ruby-2.2.0
|
55
|
+
FLICKPAPER=`which flickpaper`
|
56
|
+
if [ ! -z "$FLICKPAPER" ]; then
|
57
|
+
$FLICKPAPER
|
58
|
+
fi
|
59
|
+
```
|
60
|
+
|
37
61
|
## Contributing
|
38
62
|
|
39
63
|
1. Fork it ( https://github.com/atongen/flickpaper/fork )
|
data/flickpaper.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Flickpaper::VERSION
|
9
9
|
spec.authors = ["Andrew Tongen"]
|
10
10
|
spec.email = ["atongen@gmail.com"]
|
11
|
-
spec.summary = %q{Sets your GNOME wallpaper to a recent interesting photo from flickr}
|
12
|
-
spec.description =
|
11
|
+
spec.summary = %q{Sets your GNOME or OSX wallpaper to a recent interesting photo from flickr}
|
12
|
+
spec.description = %q{Sets your GNOME or OSX wallpaper to a recent interesting photo from flickr}
|
13
13
|
spec.homepage = "http://github.com/atongen/flickpaper"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/flickpaper.rb
CHANGED
@@ -8,7 +8,23 @@ require 'logger'
|
|
8
8
|
|
9
9
|
module Flickpaper
|
10
10
|
API_KEY = '23005d9cf8cc185c1c2d17152d03d98b'
|
11
|
-
|
11
|
+
# Shared secret not required?
|
12
|
+
SHARED_SECRET = ''
|
13
|
+
|
14
|
+
SIZES = %w{
|
15
|
+
Square
|
16
|
+
Large\ Square
|
17
|
+
Thumbnail
|
18
|
+
Small
|
19
|
+
Small\ 320
|
20
|
+
Medium
|
21
|
+
Medium\ 640
|
22
|
+
Medium\ 800
|
23
|
+
Large
|
24
|
+
Large\ 1600
|
25
|
+
Large\ 2048
|
26
|
+
Original
|
27
|
+
}
|
12
28
|
|
13
29
|
def self.init
|
14
30
|
FlickRaw.api_key = API_KEY
|
@@ -18,24 +34,44 @@ module Flickpaper
|
|
18
34
|
def self.parse_opts(opts)
|
19
35
|
options = {
|
20
36
|
dump: File.join(ENV['HOME'], '.flickpaper.dump'),
|
21
|
-
image:
|
22
|
-
log: nil
|
37
|
+
image: get_default_image_path,
|
38
|
+
log: nil,
|
39
|
+
per_page: 100,
|
40
|
+
date: nil,
|
41
|
+
page: 1,
|
42
|
+
size: 'Large 2048'
|
23
43
|
}
|
24
44
|
opt_parser = OptionParser.new do |opts|
|
25
45
|
opts.banner = "Usage: $ #{File.basename($0)} [options]"
|
26
|
-
opts.on('-d', '--dump
|
46
|
+
opts.on('-d', '--dump PATH', "Dump file for used photo ids. Default: #{options[:dump]}") do |dump|
|
27
47
|
options[:dump] = dump
|
28
48
|
end
|
29
|
-
opts.on('-i', '--image
|
49
|
+
opts.on('-i', '--image PATH', "Where to store the downloaded image. Default: #{options[:image]}") do |image|
|
30
50
|
options[:image] = image
|
31
51
|
end
|
32
|
-
opts.on('-l', '--log
|
52
|
+
opts.on('-l', '--log PATH', "Path to log file. Default: STDOUT") do |log|
|
33
53
|
options[:log] = log
|
34
54
|
end
|
35
|
-
opts.on('-
|
55
|
+
opts.on('-p', '--per-page PER_PAGE', "Number of interesting photos per page in flickr api call. Default: #{options[:per_page]}") do |per_page|
|
56
|
+
options[:per_page] = per_page
|
57
|
+
end
|
58
|
+
opts.on('--date DATE', "A specific date, formatted as YYYY-MM-DD, to return interesting photos for. Default: null (most recent)") do |date|
|
59
|
+
options[:date] = date
|
60
|
+
end
|
61
|
+
opts.on('--page PAGE', "The page of results to return. Default: #{options[:page]}") do |page|
|
62
|
+
options[:page] = page
|
63
|
+
end
|
64
|
+
opts.on('-s', '--size SIZE', "Minimum acceptable image size. Default: #{options[:size]}") do |size|
|
65
|
+
options[:size]= size
|
66
|
+
end
|
67
|
+
opts.on('-v', '--verbose', 'Be verbose.') do |verbose|
|
36
68
|
options[:verbose] = verbose
|
37
69
|
end
|
38
|
-
opts.
|
70
|
+
opts.on('--sizes', "Print sizes and exit.") do |sizes|
|
71
|
+
puts SIZES.join(', ')
|
72
|
+
exit 0
|
73
|
+
end
|
74
|
+
opts.on_tail("--version", "Show version and exit.") do
|
39
75
|
puts Flickpaper::VERSION
|
40
76
|
exit 0
|
41
77
|
end
|
@@ -44,30 +80,6 @@ module Flickpaper
|
|
44
80
|
[opts, options]
|
45
81
|
end
|
46
82
|
|
47
|
-
# date (Optional)
|
48
|
-
# A specific date, formatted as YYYY-MM-DD, to return interesting photos for.
|
49
|
-
# extras (Optional)
|
50
|
-
# A comma-delimited list of extra information to fetch for each returned record. Currently supported fields are: description, license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o
|
51
|
-
# per_page (Optional)
|
52
|
-
# Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.
|
53
|
-
# page (Optional)
|
54
|
-
# The page of results to return. If this argument is omitted, it defaults to 1.
|
55
|
-
def self.interesting(options = {})
|
56
|
-
flickr.interestingness.getList(options)
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.infos(list)
|
60
|
-
list.map do |photo|
|
61
|
-
flickr.photos.getInfo(photo_id: photo['id'])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.sizes(list)
|
66
|
-
list.map do |photo|
|
67
|
-
flickr.photos.getSizes(photo_id: photo['id'])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
83
|
def self.save_file(url, dst)
|
72
84
|
File.open(dst, 'wb') do |saved_file|
|
73
85
|
open(url, 'rb') do |read_file|
|
@@ -103,28 +115,53 @@ module Flickpaper
|
|
103
115
|
end
|
104
116
|
end
|
105
117
|
|
118
|
+
# http://apple.stackexchange.com/questions/200125/how-to-create-an-osx-application-to-wrap-a-call-to-a-shell-script
|
119
|
+
# http://www.hccp.org/command-line-os-x.html
|
120
|
+
# http://osxdaily.com/2015/08/28/set-wallpaper-command-line-macosx/
|
106
121
|
def self.set_wallpaper_macosx(path)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
122
|
+
osascript = %x{ which osascript }.to_s.strip
|
123
|
+
if osascript == ""
|
124
|
+
false
|
125
|
+
else
|
126
|
+
bash = <<-EOBASH
|
127
|
+
#{osascript} -e 'tell application "Finder" to set desktop picture to POSIX file "#{path}"'
|
128
|
+
EOBASH
|
129
|
+
system(bash)
|
130
|
+
end
|
113
131
|
end
|
114
132
|
|
115
133
|
def self.set_wallpaper_linux(path)
|
116
|
-
dbus_launch = %
|
117
|
-
|
134
|
+
dbus_launch = %x{ which dbus-launch }.to_s.strip
|
135
|
+
gsettings = %x{ which gsettings }.to_s.strip
|
136
|
+
if dbus_launch == "" || gsettings == ""
|
137
|
+
false
|
138
|
+
else
|
118
139
|
# http://dbus.freedesktop.org/doc/dbus-launch.1.html
|
119
140
|
bash = <<-EOBASH
|
120
141
|
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
|
121
142
|
# if not found, launch a new one
|
122
|
-
eval
|
143
|
+
eval `#{dbus_launch} --sh-syntax`
|
123
144
|
fi
|
124
145
|
|
125
|
-
gsettings set org.gnome.desktop.background picture-uri "file://#{path}"
|
146
|
+
#{gsettings} set org.gnome.desktop.background picture-uri "file://#{path}"
|
126
147
|
EOBASH
|
127
148
|
system(bash)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.get_default_image_path
|
153
|
+
case os
|
154
|
+
when :windows
|
155
|
+
false
|
156
|
+
when :macosx
|
157
|
+
home_tmp = File.join(ENV['HOME'], 'tmp')
|
158
|
+
if File.directory?(home_tmp)
|
159
|
+
File.join(home_tmp, "flickpaper-#{ENV['USER']}.jpg")
|
160
|
+
else
|
161
|
+
File.join('/tmp', "flickpaper-#{ENV['USER']}.jpg")
|
162
|
+
end
|
163
|
+
when :linux, :unix
|
164
|
+
File.join(ENV['HOME'], '.flickpaper.jpg')
|
128
165
|
else
|
129
166
|
false
|
130
167
|
end
|
@@ -144,10 +181,31 @@ module Flickpaper
|
|
144
181
|
log = Logger.new(options[:log] ? options[:log] : STDOUT)
|
145
182
|
log.level = options[:verbose] ? Logger::INFO : Logger::ERROR
|
146
183
|
|
184
|
+
size_idx = SIZES.index(options[:size])
|
185
|
+
if size_idx.nil? || size_idx < 0
|
186
|
+
log.error("Invalid size argument: #{options[:size]}.\nPlease select from: #{SIZES.join(', ')}.")
|
187
|
+
exit 1
|
188
|
+
end
|
189
|
+
|
147
190
|
Flickpaper.init
|
148
191
|
|
149
|
-
|
150
|
-
|
192
|
+
opts = options.select { |k,v| [:page, :per_page, :date].include?(k) && !v.nil? }
|
193
|
+
log.info("Getting interesting list: #{opts.inspect}")
|
194
|
+
begin
|
195
|
+
# date (Optional)
|
196
|
+
# A specific date, formatted as YYYY-MM-DD, to return interesting photos for.
|
197
|
+
# extras (Optional)
|
198
|
+
# A comma-delimited list of extra information to fetch for each returned record. Currently supported fields are: description, license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o
|
199
|
+
# per_page (Optional)
|
200
|
+
# Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.
|
201
|
+
# page (Optional)
|
202
|
+
# The page of results to return. If this argument is omitted, it defaults to 1.
|
203
|
+
list = flickr.interestingness.getList(opts)
|
204
|
+
rescue FlickRaw::FailedResponse => e
|
205
|
+
log.error("Flickr API error: #{e.message}")
|
206
|
+
exit 1
|
207
|
+
end
|
208
|
+
|
151
209
|
ids = Flickpaper.get_ids(options[:dump])
|
152
210
|
list = list.select { |l| !ids.include?(l['id']) }
|
153
211
|
|
@@ -156,8 +214,17 @@ module Flickpaper
|
|
156
214
|
|
157
215
|
log.info("Selecting large photo")
|
158
216
|
(0...(list.length)).each do |i|
|
159
|
-
|
160
|
-
|
217
|
+
begin
|
218
|
+
size = flickr.photos.getSizes(photo_id: list[i]['id'])
|
219
|
+
rescue FlickRaw::FailedResponse => e
|
220
|
+
log.error("Flickr API error: #{e.message}")
|
221
|
+
exit 1
|
222
|
+
end
|
223
|
+
my_size = size.detect do |s|
|
224
|
+
my_size_idx = SIZES.index(s['label'])
|
225
|
+
!my_size_idx.nil? && my_size_idx >= size_idx
|
226
|
+
end
|
227
|
+
if my_size
|
161
228
|
idx = i
|
162
229
|
url = my_size['source']
|
163
230
|
break
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickpaper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Tongen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,50 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
56
|
-
# Flickpaper
|
57
|
-
|
58
|
-
A [Flickr App](https://www.flickr.com/services/apps/72157658406991003) that sets your GNOME wallpaper to a recent interesting photo
|
59
|
-
|
60
|
-
## Installation
|
61
|
-
|
62
|
-
Install the gem:
|
63
|
-
|
64
|
-
```shell
|
65
|
-
$ gem install flickpaper
|
66
|
-
```
|
67
|
-
|
68
|
-
Or add this line to your application's Gemfile:
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
gem 'flickpaper'
|
72
|
-
```
|
73
|
-
|
74
|
-
And then execute:
|
75
|
-
|
76
|
-
```shell
|
77
|
-
$ bundle
|
78
|
-
```
|
79
|
-
|
80
|
-
## Usage
|
81
|
-
|
82
|
-
```shell
|
83
|
-
Usage: $ flickpaper [options]
|
84
|
-
-d, --dump [PATH] Dump file for used photo ids. Default: $HOME/.flickpaper.dump
|
85
|
-
-i, --image [PATH] Where to store the downloaded image. Default: $HOME/.flickpaper.jpg
|
86
|
-
-v, --verbose Verbose
|
87
|
-
--version Show version
|
88
|
-
```
|
89
|
-
|
90
|
-
Use with cron to periodically get a new interesting desktop wallpaper.
|
91
|
-
|
92
|
-
## Contributing
|
93
|
-
|
94
|
-
1. Fork it ( https://github.com/atongen/flickpaper/fork )
|
95
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
96
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
97
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
98
|
-
5. Create a new Pull Request
|
55
|
+
description: Sets your GNOME or OSX wallpaper to a recent interesting photo from flickr
|
99
56
|
email:
|
100
57
|
- atongen@gmail.com
|
101
58
|
executables:
|
@@ -137,6 +94,5 @@ rubyforge_project:
|
|
137
94
|
rubygems_version: 2.4.5
|
138
95
|
signing_key:
|
139
96
|
specification_version: 4
|
140
|
-
summary: Sets your GNOME wallpaper to a recent interesting photo from flickr
|
97
|
+
summary: Sets your GNOME or OSX wallpaper to a recent interesting photo from flickr
|
141
98
|
test_files: []
|
142
|
-
has_rdoc:
|