bingwallpaper 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTI4MWMxNjg1NzM2NWVjNDMzMDFlMzE3YzlkMmM1ZDVmNDI4ZjgwMw==
5
+ data.tar.gz: !binary |-
6
+ MzQ1NGFlNzFkMGQyYzY2ZThlNTQwOTU3Y2UwYmM1ZDhmNzE5Yzc2Yw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTcxYjc3Zjc2NDBmNDQ5OTViNzA0YjA2NWNkM2IxMjZiNDMyNzlmNDlkODVl
10
+ ZjlhMzNmZWY1M2MwYTczZGVmMTk0NTc1Y2FhMzViODJkYzQ0MDIzNTAwZDgz
11
+ ZjkzMDJkNjUwOWYwNmZlMzdjNGY1NTliYjYzZjhmYzg2YzIyZGY=
12
+ data.tar.gz: !binary |-
13
+ OGMzOTYxMDJlNGVjNDBjOGJhNDgzYmRhZDE3ZjVjZjM0OWI3MGFiZTNiOGRh
14
+ MjUzOTRiMzI1ODIwYjI0ZmI5YzlmODY4NmVlZGUwMWQxNmIzYTNkN2Y3NmQx
15
+ YWIyODM3NThhMGQxYjllN2RhZjhkM2EzODQxMjIzMzk5ZDk5ZGM=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bingwallpaper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 cmiles74
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,29 @@
1
+ # Bing Wallpaper
2
+
3
+ This project provides a simple Ruby script that will download the
4
+ "Image of the Day" from [Bing][0] and then sets it as your current
5
+ wallpaper.
6
+
7
+ ## How It Works
8
+
9
+ I wrote this script with my own environment in mind, so it's pretty
10
+ simple-minded. It fetches the XML describing today's image, then
11
+ fetches the 1920x1200 sized version. Lastly, it uses [Feh][1] to set
12
+ the wallpaper for your environment. I've tested it in [i3][2] and
13
+ nowhere else.
14
+
15
+ ## Using the Script
16
+
17
+ Just install the gem...
18
+
19
+ gem install bingwallpaper
20
+
21
+ And then invoke the script.
22
+
23
+ bing-wallpaper
24
+
25
+
26
+ ***
27
+ [0]: https://www/bing.com
28
+ [1]: http://feh.finalrewind.org/
29
+ [2]: http://i3wm.org/
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/bingwallpaper ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ #-*- mode: enh-ruby;-*-
3
+
4
+ #
5
+ # Sets the desktop wallpaper to the current "image of the day" from the Bing
6
+ # search engine.
7
+ #
8
+
9
+ require "bingwallpaper"
10
+
11
+ # create an instance and set the wallpaper
12
+ bingImage = Bingwallpaper::Image.new
13
+
14
+ # set the wallpaper
15
+ begin
16
+ bingImage.set_today_wallpaper
17
+ rescue Exception => exception
18
+ puts "Sorry, I couldn't set today's Bing Imagee of the Day Wallpaper. :'("
19
+ puts exception.message
20
+ exit 1
21
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bingwallpaper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bingwallpaper"
8
+ spec.version = Bingwallpaper::VERSION
9
+ spec.authors = ["cmiles74"]
10
+ spec.email = ["twitch@nervestaple.com"]
11
+ spec.summary = %q{Write a short summary. Required.}
12
+ spec.description = %q{Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables << "bingwallpaper"
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,6 @@
1
+ require "bingwallpaper/version"
2
+ require "bingwallpaper/image"
3
+
4
+ module Bingwallpaper
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,135 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+
6
+ module Bingwallpaper
7
+
8
+ #
9
+ # Provides a class that queries and fetches the Bing "image of the day".
10
+ #
11
+ class Image
12
+
13
+ # Protocol for accessing Bing
14
+ PROTO = 'https://'
15
+
16
+ # Current Bing domain
17
+ DOMAIN = 'www.bing.com'
18
+
19
+ # Path for the image archive
20
+ PATH = '/HPImageArchive.aspx'
21
+
22
+ # Format for retrieving data
23
+ FORMAT = 'xml'
24
+
25
+ # Default market to fetch
26
+ DEFAULT_MARKET = 'en-US'
27
+
28
+ # Default index to fetch (today)
29
+ DEFAULT_INDEX = 0
30
+
31
+ # Default storage path
32
+ DEFAULT_STORAGE_PATH = ENV['HOME'] + '/.config/bing_wallpaper'
33
+
34
+ # Market to fetch
35
+ attr_accessor :market
36
+
37
+ # index to fetch
38
+ attr_accessor :index
39
+
40
+ # path for storing downloaded images
41
+ attr_accessor :storage_path
42
+
43
+ # Creates a new instance.
44
+ #
45
+ # market:: The market to use when fetching
46
+ # index:: Index of the image to fetch (0 = today)
47
+ # storage_path:: Path to directory for storing images
48
+ def initialize(market = DEFAULT_MARKET, index = DEFAULT_INDEX, storage_path = DEFAULT_STORAGE_PATH)
49
+
50
+ @market = market
51
+ @index = index
52
+ @storage_path = storage_path
53
+
54
+ # Ensure the storage path exists
55
+ FileUtils.mkpath storage_path
56
+ end
57
+
58
+ # Constructs a full path for the provided partial URL.
59
+ #
60
+ # partial:: the end of the target URL
61
+ def build_url(partial)
62
+
63
+ return PROTO + DOMAIN + partial
64
+ end
65
+
66
+ # Returns the data URL for the image of the day.
67
+ def get_data_url
68
+
69
+ return build_url(PATH + '?format=' + FORMAT + '&idx=' + @index.to_s + '&n=1' + '&mkt=' + @market)
70
+ end
71
+
72
+ # Parses the XML data and returns a hash of image information.
73
+ #
74
+ # url:: complete path to the Bing image of the day
75
+ def parse_xml(url)
76
+
77
+ doc = Nokogiri::HTML(open(url))
78
+
79
+ doc.xpath('//images/image').map do |image|
80
+
81
+ # figure out the hi-res image path
82
+ image_path = image.xpath('url').text.sub(image.xpath('url').text.rpartition("_").
83
+ last, '1920x1200.jpg')
84
+
85
+ # build our hash of image data
86
+ {:links => {:url => build_url(image_path),
87
+ :copyright_url => image.xpath('copyrightlink').text},
88
+ :file_name => Pathname.new(image_path).basename.to_s,
89
+ :copyright => image.xpath('copyright').text}
90
+ end
91
+ end
92
+
93
+ # Returns the file location where the image from the provided Bing image
94
+ # hash will be stored.
95
+ #
96
+ # image_data:: Hash of Bing image data
97
+ def image_storage_path(image_data)
98
+ @storage_path + "/" + image_data[:file_name]
99
+ end
100
+
101
+ # Downloads the Bing image from the provided image hash.
102
+ #
103
+ # image_date:: Hash of Bing image data
104
+ def download_image(image_data)
105
+
106
+ open(image_storage_path(image_data), 'wb') do |file|
107
+ puts "Downloading: " + image_data[:links][:url]
108
+ file << open(image_data[:links][:url]).read
109
+ end
110
+ end
111
+
112
+ # Sets the current wallpaper to the provide File instance.
113
+ #
114
+ # file:: File instance with wallpaper data
115
+ def set_wallpaper(file)
116
+
117
+ puts "Setting wallpaper to " + file.path
118
+ `feh --bg-fill #{file.path}`
119
+ end
120
+
121
+ # Sets the wallpaper to Bing's "image of the day".
122
+ def set_today_wallpaper
123
+
124
+ image_data = parse_xml(get_data_url)
125
+ image_path = Pathname.new(image_storage_path(image_data[0]))
126
+
127
+ # only download the wallpaper once
128
+ if !image_path.exist?
129
+ set_wallpaper(download_image(image_data[0]))
130
+ else
131
+ puts "Today's wallpaper already downloaded. ;-)"
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,3 @@
1
+ module Bingwallpaper
2
+ VERSION = "0.5.0"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bingwallpaper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - cmiles74
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Write a longer description. Optional.
42
+ email:
43
+ - twitch@nervestaple.com
44
+ executables:
45
+ - bingwallpaper
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/bingwallpaper
55
+ - bingwallpaper.gemspec
56
+ - lib/bingwallpaper.rb
57
+ - lib/bingwallpaper/image.rb
58
+ - lib/bingwallpaper/version.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Write a short summary. Required.
83
+ test_files: []