flickpaper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9deac4e1943d13926359e4889df91d14a7276c1
4
+ data.tar.gz: 6e05ee5e5a2d17e8914bc807bd2954be819f2726
5
+ SHA512:
6
+ metadata.gz: 66baa9e9f1ded8e026a0ac4b2a0afd443cd5a6aab5d85851ea727d09da5c6210fc55cf90340fc108376625c219eec313f8c3f4cb1a65c515e89cae6143cb21b4
7
+ data.tar.gz: faa29407851cd513bd0a45e6a0e4e4d7097618296c6fbe1bb394d9809a8b3bd4f8919db0d7dd851487503d04a9a6ee3eb767fcfd60494c3c99a85370191b74f1
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flickpaper.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flickpaper (0.0.1)
5
+ flickraw
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ flickraw (0.9.8)
11
+ rake (10.4.2)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.7)
18
+ flickpaper!
19
+ rake (~> 10.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Andrew Tongen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Flickpaper
2
+
3
+ A [Flickr App](https://www.flickr.com/services/apps/72157658406991003) that sets your GNOME wallpaper to a recent interesting photo
4
+
5
+ ## Installation
6
+
7
+ Install the gem:
8
+
9
+ ```shell
10
+ $ gem install flickpaper
11
+ ```
12
+
13
+ Or add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'flickpaper'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```shell
22
+ $ bundle
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```shell
28
+ Usage: $ flickpaper [options]
29
+ -d, --dump [PATH] Dump file for used photo ids. Default: $HOME/.flickpaper.dump
30
+ -i, --image [PATH] Where to store the downloaded image. Default: $HOME/.flickpaper.jpg
31
+ -v, --verbose Verbose
32
+ --version Show version
33
+ ```
34
+
35
+ Use with cron to periodically get a new interesting desktop wallpaper.
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/atongen/flickpaper/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/flickpaper ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+ # vi: set ft=ruby :
4
+
5
+ lib = File.expand_path('../../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
7
+ require 'flickpaper'
8
+ Flickpaper.run!
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flickpaper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flickpaper"
8
+ spec.version = Flickpaper::VERSION
9
+ spec.authors = ["Andrew Tongen"]
10
+ spec.email = ["atongen@gmail.com"]
11
+ spec.summary = %q{Sets your GNOME wallpaper to a recent interesting photo from flickr}
12
+ spec.description = IO.read(File.join(File.dirname(__FILE__), 'README.md'))
13
+ spec.homepage = "http://github.com/atongen/flickpaper"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency 'flickraw'
25
+ end
@@ -0,0 +1,3 @@
1
+ module Flickpaper
2
+ VERSION = File.read(File.expand_path('../../../version', __FILE__)).to_s.strip
3
+ end
data/lib/flickpaper.rb ADDED
@@ -0,0 +1,139 @@
1
+ require "flickpaper/version"
2
+
3
+ require 'flickraw'
4
+ require 'optparse'
5
+ require 'open-uri'
6
+
7
+ module Flickpaper
8
+ API_KEY = '23005d9cf8cc185c1c2d17152d03d98b'
9
+ SHARED_SECRET = 'a6e67612f607b407'
10
+
11
+ def self.init
12
+ FlickRaw.api_key = API_KEY
13
+ FlickRaw.shared_secret = SHARED_SECRET
14
+ end
15
+
16
+ def self.parse_opts(opts)
17
+ options = {
18
+ dump: File.join(ENV['HOME'], '.flickpaper.dump'),
19
+ image: File.join(ENV['HOME'], '.flickpaper.jpg')
20
+ }
21
+ opt_parser = OptionParser.new do |opts|
22
+ opts.banner = "Usage: $ #{File.basename($0)} [options]"
23
+ opts.on('-d', '--dump [PATH]', "Dump file for used photo ids. Default: #{options[:dump]}") do |dump|
24
+ options[:dump] = dump
25
+ end
26
+ opts.on('-i', '--image [PATH]', "Where to store the downloaded image. Default: #{options[:image]}") do |image|
27
+ options[:image] = image
28
+ end
29
+ opts.on('-v', '--verbose', 'Verbose') do |verbose|
30
+ options[:verbose] = verbose
31
+ end
32
+ opts.on_tail("--version", "Show version") do
33
+ puts Flickpaper::VERSION.map(&:to_s).join('.')
34
+ exit
35
+ end
36
+ end
37
+ opt_parser.parse!(opts)
38
+ [opts, options]
39
+ end
40
+
41
+ # date (Optional)
42
+ # A specific date, formatted as YYYY-MM-DD, to return interesting photos for.
43
+ # extras (Optional)
44
+ # 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
45
+ # per_page (Optional)
46
+ # Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.
47
+ # page (Optional)
48
+ # The page of results to return. If this argument is omitted, it defaults to 1.
49
+ def self.interesting(options = {})
50
+ flickr.interestingness.getList(options)
51
+ end
52
+
53
+ def self.infos(list)
54
+ list.map do |photo|
55
+ flickr.photos.getInfo(photo_id: photo['id'])
56
+ end
57
+ end
58
+
59
+ def self.sizes(list)
60
+ list.map do |photo|
61
+ flickr.photos.getSizes(photo_id: photo['id'])
62
+ end
63
+ end
64
+
65
+ def self.sort_infos(infos)
66
+ sort_vals = infos.inject({}) do |sort_vals, info|
67
+ sort_vals[info['id']] = (info['views'].to_f ** 0.5) * (info['comments'].to_f ** 0.5)
68
+ sort_vals
69
+ end
70
+
71
+ infos.sort do |x,y|
72
+ sort_vals[y['id']] <=> sort_vals[x['id']]
73
+ end
74
+ end
75
+
76
+ def self.save_file(url, dst)
77
+ File.open(dst, 'wb') do |saved_file|
78
+ open(url, 'rb') do |read_file|
79
+ saved_file.write(read_file.read)
80
+ end
81
+ end
82
+ end
83
+
84
+ def self.set_wallpaper(path)
85
+ bash = <<-EOBASH
86
+ sessionfile=`find "${HOME}/.dbus/session-bus/" -type f`
87
+ eval `cat ${sessionfile}`
88
+ export DBUS_SESSION_BUS_ADDRESS \
89
+ DBUS_SESSION_BUS_PID \
90
+ DBUS_SESSION_BUS_WINDOWID
91
+
92
+ gsettings set org.gnome.desktop.background picture-uri "file://#{path}"
93
+ EOBASH
94
+ system(bash)
95
+ end
96
+
97
+ def self.get_ids(file)
98
+ File.file?(file) ? Marshal.load(File.read(file)) : []
99
+ end
100
+
101
+ def self.put_ids(file, ids)
102
+ File.open(file, 'wb') { |f| f << Marshal.dump(ids) }
103
+ ids
104
+ end
105
+
106
+ def self.run!
107
+ arguments, options = Flickpaper.parse_opts(ARGV.dup)
108
+ Flickpaper.init
109
+
110
+ list = Flickpaper.interesting
111
+ ids = Flickpaper.get_ids(options[:dump])
112
+ list = list.select { |l| !ids.include?(l['id']) }
113
+ infos = Flickpaper.sort_infos(Flickpaper.infos(list))
114
+ sorted_list = infos.map do |info|
115
+ list.detect { |photo| photo['id'] == info['id'] }
116
+ end
117
+ sizes = Flickpaper.sizes(sorted_list)
118
+
119
+ idx = nil
120
+ url = nil
121
+
122
+ (0...(sizes.length)).each do |i|
123
+ if my_size = sizes[i].detect { |s| s['label'] == "Large 2048" }
124
+ idx = i
125
+ url = my_size['source']
126
+ break
127
+ end
128
+ end
129
+
130
+ if idx
131
+ my_photo = sorted_list[idx]
132
+ my_info = infos[idx]
133
+
134
+ Flickpaper.save_file(url, options[:image])
135
+ Flickpaper.set_wallpaper(options[:image])
136
+ Flickpaper.put_ids(options[:dump], ids<<my_photo['id'])
137
+ end
138
+ end
139
+ end
data/version ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flickpaper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Tongen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: flickraw
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
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
99
+ email:
100
+ - atongen@gmail.com
101
+ executables:
102
+ - flickpaper
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/flickpaper
113
+ - flickpaper.gemspec
114
+ - lib/flickpaper.rb
115
+ - lib/flickpaper/version.rb
116
+ - version
117
+ homepage: http://github.com/atongen/flickpaper
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.5
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Sets your GNOME wallpaper to a recent interesting photo from flickr
141
+ test_files: []
142
+ has_rdoc: