hexapic 0.1.0

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: e084bbb05a28b2f06235d02848a338516fb6c1bb
4
+ data.tar.gz: e291e4edd692bb7fada97295aa27d44d3e7c0a24
5
+ SHA512:
6
+ metadata.gz: 2fe9318a024056074e038b8c49336e43d8b6999775e579ac5072d87e84aea1a86282849919ad90c1069173ad618bae360e64d31c3d4aa21199937032bc5ffe38
7
+ data.tar.gz: f33f86e1899247cbfb63c14efa6afe60514211b79bfdec5c2d035e88596d7f115f8fa98fd480d08c3cb240fcef8cb0b0d909297bc5ccd487d730454c86b495c8
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ vendor/bundle
2
+ .bundle/
3
+ .yardoc
4
+ Gemfile.lock
5
+ _yardoc/
6
+ coverage/
7
+ doc/
8
+ pkg/
9
+ spec/reports/
10
+ tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ .rvmrc
18
+ .ruby-version
19
+ .ruby-gemset
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ #ruby-gemset=hexapic
4
+ #ruby=2.1.4
5
+
6
+ # Specify your gem's dependencies in hexapic.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ilya Siganov
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 @@
1
+ # Hexapic
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
9
+
data/bin/hexapic ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'hexapic'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'hexapic'
8
+ end
9
+
10
+ include Hexapic
11
+ require 'choice'
12
+
13
+ def help
14
+ puts 'TODO: write help'
15
+ end
16
+
17
+ def set_wallpaper
18
+ tags = Choice.choices[:tags] || ENV['WALLPAPER_TAGS'] || 'nature'
19
+ repository = Choice.choices[:repository] || ENV['WALLPAPER_REPOSITPRY'] || :instagram
20
+ runner = Hexapic::Runner.new(tags)
21
+ runner.run(repository)
22
+ end
23
+
24
+ def print_version
25
+ puts Hexapic::VERSION
26
+ exit 0
27
+ end
28
+
29
+ Choice.options do
30
+ option :version do
31
+ long '--version'
32
+ short '-v'
33
+ desc 'print version and exit'
34
+ action { print_version }
35
+ end
36
+
37
+ option :repository do
38
+ long '--repository=REPOSITORY'
39
+ short '-r'
40
+ desc 'Chose where to load pictures. Chose one of flickr, instagram.'
41
+ cast Symbol
42
+ end
43
+
44
+ option :tags do
45
+ long '--tags=TAGS'
46
+ short '-t'
47
+ desc 'comma separated list of tags'
48
+ cast String
49
+ end
50
+ end
51
+
52
+ if Choice.choices[:tags]
53
+ begin
54
+ set_wallpaper
55
+ rescue Exception => e
56
+ puts e.message
57
+ end
58
+ elsif Choice.choices[:version]
59
+ print_version
60
+ else
61
+ help
62
+ end
data/hexapic.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hexapic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hexapic'
8
+ spec.version = Hexapic::VERSION
9
+ spec.authors = ['Ilya Siganov']
10
+ spec.email = ['ilya.blan4@gmail.com']
11
+ spec.summary = 'Set desktop wallpaper from social networks'
12
+ spec.description = "Pick a 6 latest pics from flickr, instagram or twitter, make collage of its and set it as Linux's background."
13
+ spec.homepage = 'https://github.com/blan4/Hexapic'
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.requirements << 'imagemagick'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'minitest', '~> 5.4'
26
+ spec.add_runtime_dependency 'choice', '~> 0.1'
27
+ spec.add_runtime_dependency 'flickr.rb', '~> 1.2'
28
+ spec.add_runtime_dependency 'instagram', '~> 1.1'
29
+ spec.add_runtime_dependency 'mini_magick', '~> 4.0'
30
+ end
@@ -0,0 +1,36 @@
1
+ require 'mini_magick'
2
+ require 'tempfile'
3
+ module Hexapic
4
+ class Collage
5
+ attr_reader :height, :width
6
+
7
+ def make(pictures)
8
+ puts 'Start collage'
9
+ if pictures.size == 1
10
+ Downloader.get pictures.first
11
+ else
12
+ images = []
13
+ file_path = Downloader.generate_file_path
14
+ pictures.map.with_index do |picture,index|
15
+ Thread.new(index) do |i|
16
+ picture = Downloader.get(picture) if picture.path.nil?
17
+ images[i] = picture.path
18
+ end
19
+ end.each{ |thr| thr.join }
20
+
21
+ puts "Make collage and save to #{file_path}"
22
+ MiniMagick::Tool::Montage.new do |m|
23
+ m << '-mode'
24
+ m << 'concatenate'
25
+ m << '-tile'
26
+ m << '3x2'
27
+ images.each{|img| m << img}
28
+ m << file_path
29
+ end
30
+
31
+ puts file_path
32
+ Repository::Picture.new('','','', file_path)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ require 'open3'
2
+
3
+ module Hexapic
4
+ class DesktopEnvironment
5
+ DE = {'Metacity (Marco)'=> :mate, 'Xfwm4'=> :xfce4, 'Gnome3'=> :gnome3, 'Mutter (Muffin)'=> :cinnamon}
6
+
7
+ def self.which
8
+ wm_name = nil
9
+
10
+ Open3.popen3('xprop', '-root', '_NET_SUPPORTING_WM_CHECK') do |inp, out, err|
11
+ inp.close
12
+ err.close
13
+ winpdow_id = out.gets.split('#').last.strip
14
+ out.close
15
+ Open3.popen3('xprop', '-id', winpdow_id, '8s', '_NET_WM_NAME') do |inp, out, err|
16
+ inp.close
17
+ err.close
18
+ wm_name = out.gets.split('=').last.strip.gsub('"','')
19
+ end
20
+ end
21
+
22
+ DE[wm_name]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ require 'fileutils'
2
+
3
+ module Hexapic
4
+ class Downloader
5
+ def self.get(picture)
6
+ file_path = self.generate_file_path(picture.filename)
7
+
8
+ puts "Downloading #{picture.url}"
9
+ File.open(file_path, 'w') do |f|
10
+ f.puts Net::HTTP.get_response(URI.parse(picture.url)).body
11
+ end
12
+
13
+ res = picture.clone
14
+ res.path = File.absolute_path(file_path)
15
+ res
16
+ end
17
+
18
+ def self.generate_file_path(filename = nil)
19
+ filename ||= (0...8).map { (65 + rand(26)).chr }.join + '.jpg'
20
+ pictures_dir = File.join(Dir.home, 'Pictures', 'hexapic')
21
+ FileUtils.mkdir_p(pictures_dir) unless Dir.exists? pictures_dir
22
+
23
+ File.join(pictures_dir, filename)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,84 @@
1
+ require 'flickr'
2
+ require 'instagram'
3
+ require 'uri'
4
+ module Hexapic
5
+ module Repository
6
+ COUNT = 6
7
+
8
+ class TestRepository
9
+ def initialize
10
+ puts 'Using Local Dir'
11
+ end
12
+
13
+ def find_pictures(tag)
14
+ path = "/home/ilya/Pictures/wallpaper/10810006_1487374498191383_1977583548_n.jpg"
15
+ (1..COUNT).map { Picture.new(path, path, path, path) }
16
+ end
17
+ end
18
+
19
+ class InstagramRepository
20
+ CLIENT_ID = '417c3ee8c9544530b83aa1c24de2abb3'
21
+
22
+ def initialize
23
+ @instagram = Instagram.client(client_id: CLIENT_ID)
24
+ puts 'Using Instagram'
25
+ end
26
+
27
+ def find_pictures(tag)
28
+ tag = URI.encode(tag.split(',').first)
29
+ puts "Getting last images by tag #{tag}"
30
+ pics = @instagram.tag_recent_media(tag).sample(COUNT).map do |r|
31
+ url = r.images.standard_resolution.url
32
+ Picture.new(url, url, url.split('/').last)
33
+ end
34
+
35
+ raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT
36
+ pics
37
+ rescue Exception => e
38
+ raise NoInternet.new(e.message)
39
+ end
40
+ end
41
+
42
+ class FlickrRepository
43
+ API_KEY = 'bd053065ce6662cb4b2f4c0be2b65266'
44
+
45
+ def initialize
46
+ @flickr = Flickr.new(api_key: API_KEY, verify_ssl: false)
47
+ puts 'Using Flickr'
48
+ end
49
+
50
+ def find_pictures(tags)
51
+ options = {}
52
+ options[:tag_mode] = 'and'
53
+ options[:tags] = tags
54
+ options[:sort] = 'relevance'
55
+ options[:content_type] = '1'
56
+ options[:extras] = 'url_q,url_sq,url_s'
57
+ puts "Getting last images by tags #{tags}"
58
+ pics = @flickr.search(options).sample(COUNT).map do |photo|
59
+ Picture.new(photo.source('Large Square'), photo.url, photo.filename)
60
+ end
61
+
62
+ raise ImagesNotFound.new("Found only #{pics.size} images. Need #{COUNT}.") if pics.size < COUNT
63
+ pics
64
+ rescue Exception => e
65
+ raise NoInternet.new(e.message)
66
+ end
67
+ end
68
+
69
+ class Picture
70
+ attr_accessor :url, :post_url, :filename, :path
71
+
72
+ def initialize(url, post_url, filename, path = nil)
73
+ @url = url
74
+ @post_url = post_url
75
+ @filename = filename
76
+ @path = path
77
+ end
78
+ end
79
+
80
+ class ImagesNotFound < StandardError; end
81
+ class NoInternet < StandardError; end
82
+ LIST = {flickr: FlickrRepository, instagram: InstagramRepository}
83
+ end
84
+ end
@@ -0,0 +1,17 @@
1
+ module Hexapic
2
+ class Runner
3
+ def initialize(tags)
4
+ @tags = tags.to_s
5
+ end
6
+
7
+ def run(repository = :instagram)
8
+ collage = Collage.new
9
+ setter = WallpaperSetter.build
10
+ repository = Repository::LIST[repository].new
11
+ pictures = repository.find_pictures(@tags)
12
+ picture = collage.make(pictures)
13
+
14
+ setter.set picture.path
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Hexapic
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "desktop_environment"
2
+ module Hexapic
3
+ module WallpaperSetter
4
+ class XFCE4
5
+ def set(path)
6
+ command = "xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorLVDS1/workspace1/last-image -s #{path}"
7
+ system command
8
+ end
9
+ end
10
+
11
+ class Gnome3
12
+ def set(path)
13
+ comand = "gsettings set org.gnome.desktop.background picture-uri file:///#{path}"
14
+ system comand
15
+ end
16
+ end
17
+
18
+ class Mate
19
+ def set(path)
20
+ comand = "gsettings set org.mate.background picture-filename #{path}"
21
+ system comand
22
+ end
23
+ end
24
+
25
+ class KDE4
26
+ def set(path)
27
+ comand = "dbus-send --session --dest=org.new_wallpaper.Plasmoid --type=method_call /org/new_wallpaper/Plasmoid/0 org.new_wallpaper.Plasmoid.SetWallpaper string:#{path}"
28
+ system comand
29
+ end
30
+ end
31
+
32
+ DE = {mate: Mate, gnome3: Gnome3, xfce4: XFCE4, kde4: KDE4}
33
+
34
+ def self.build
35
+ klass = DE[DesktopEnvironment.which]
36
+ klass.new unless klass.nil?
37
+ end
38
+ end
39
+ end
data/lib/hexapic.rb ADDED
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('.')
2
+
3
+ require 'hexapic/version'
4
+ require 'hexapic/wallpaper_setter'
5
+ require 'hexapic/repository'
6
+ require 'hexapic/downloader'
7
+ require 'hexapic/collage'
8
+
9
+ require 'hexapic/runner'
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'hexapic'
3
+
4
+ require 'minitest/autorun'
@@ -0,0 +1,7 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestHexapic < MiniTest::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Hexapic::VERSION
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hexapic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Siganov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-15 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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: choice
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: flickr.rb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: instagram
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mini_magick
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
111
+ description: Pick a 6 latest pics from flickr, instagram or twitter, make collage
112
+ of its and set it as Linux's background.
113
+ email:
114
+ - ilya.blan4@gmail.com
115
+ executables:
116
+ - hexapic
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/hexapic
127
+ - hexapic.gemspec
128
+ - lib/hexapic.rb
129
+ - lib/hexapic/collage.rb
130
+ - lib/hexapic/desktop_environment.rb
131
+ - lib/hexapic/downloader.rb
132
+ - lib/hexapic/repository.rb
133
+ - lib/hexapic/runner.rb
134
+ - lib/hexapic/version.rb
135
+ - lib/hexapic/wallpaper_setter.rb
136
+ - test/minitest_helper.rb
137
+ - test/test_hexapic.rb
138
+ homepage: https://github.com/blan4/Hexapic
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements:
157
+ - imagemagick
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Set desktop wallpaper from social networks
163
+ test_files:
164
+ - test/minitest_helper.rb
165
+ - test/test_hexapic.rb