bingwallpaper 0.6.0 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8c7d463413b4ff8a8acb349f42da411983ae8d73
4
- data.tar.gz: 29eb28625a0733fa4fca25f4d2bf071f34780bf9
2
+ SHA256:
3
+ metadata.gz: 7e6a6a1630ffd35d35e5b1b2c68fcaea45fc24727c43bacd4f457f1e4badfc71
4
+ data.tar.gz: cefaa7ceea9c8b20cbaed88fb60339a47dc18b72623eb2dc2de40f12488d69e3
5
5
  SHA512:
6
- metadata.gz: 889e2ac347079fe55df1d2b1a5a0a5b158dec4a640b92fdb0c3cae7d00cb561b156784efe3d4abd0bc2d441ffaca5f6d51de7ea3fe936cdd245a98500992bd14
7
- data.tar.gz: e542578c1fc8b3698c2d21e4af81812a13c4aac9cdd63d7e1b9fc27b8217a45bca560900a766f45e6bd73ca800094bcc0991714e19f18c3fa15bf67dec80c9cf
6
+ metadata.gz: c0a91dbe4c37cfae2ce6b29b591e709f68bbef97a56c604f99dfd2fc99daa0b91cf621ad0933945eddac9284b962b1cac7c3269063ba85269b0a0a1ccf6d0e79
7
+ data.tar.gz: 20b41d3655b17b0e9d0f8c9f0c82af8d6c27f523b06f914c4339af1fb14e23e4d88ea01efa8cf7b44e90ef3e8a11136d91138450a23c4948f58527aa709717bc
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.2
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'irb', require: false
4
+
3
5
  # Specify your gem's dependencies in bingwallpaper.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  [![Gem Version](https://badge.fury.io/rb/bingwallpaper.svg)](http://badge.fury.io/rb/bingwallpaper)
2
3
 
3
4
  # Bing Wallpaper
@@ -6,13 +7,18 @@ This project provides a simple Ruby script that will download the
6
7
  "Image of the Day" from [Bing][0] and then sets it as your current
7
8
  wallpaper.
8
9
 
10
+ If you find this code useful in any way, please feel free to...
11
+
12
+ <a href="https://www.buymeacoffee.com/cmiles74" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
13
+
14
+
9
15
  ## How It Works
10
16
 
11
17
  I wrote this script with my own environment in mind, so it's pretty
12
- simple-minded. It fetches the XML describing today's image, then fetches
13
- the 1920x1200 sized version. Lastly, it uses [Feh][1] or Gnome to set
14
- the wallpaper for your environment. I've tested it in [i3][2] and Gnome
15
- 3.14.2 and nowhere else.
18
+ simple-minded. It fetches the XML describing today's image, then fetches the
19
+ 1920x1200 sized version if it's available, the lower resolution version if not.
20
+ Lastly, it uses [Feh][1] or Gnome to set the wallpaper for your environment.
21
+ I've tested it in [i3][2] and Gnome 3.14.2 and nowhere else.
16
22
 
17
23
  ## Using the Script
18
24
 
data/bin/bingwallpaper CHANGED
@@ -8,6 +8,7 @@
8
8
  require "bingwallpaper"
9
9
  require "logger"
10
10
  require "optparse"
11
+ require "yaml"
11
12
 
12
13
  # setup a logger
13
14
  logger = Logger.new(STDOUT)
@@ -33,6 +34,10 @@ OptionParser.new do |opts|
33
34
  options[:feh] = f
34
35
  end
35
36
 
37
+ opts.on("-s", "--sway", "Use swaymsg to set the background, overwrite ~/.config/sway/config.d/wallpaper") do |s|
38
+ options[:sway] = s
39
+ end
40
+
36
41
  opts.on("-h", "--help", "Prints this help") do
37
42
  puts opts
38
43
  exit
@@ -42,6 +47,18 @@ end.parse!
42
47
  # create an instance and set the wallpaper
43
48
  bingImage = Bingwallpaper::Image.new
44
49
 
50
+ # bail out if we've already downloaded today's image
51
+ downloaded_data_path = bingImage.image_storage_path ".bingwallpaper"
52
+ if File.exist? downloaded_data_path
53
+
54
+ downloaded_data = YAML.load_file downloaded_data_path
55
+ if downloaded_data[:downloaded] == Date.today
56
+
57
+ logger.info "Image of the day already downloaded and set"
58
+ exit 0
59
+ end
60
+ end
61
+
45
62
  begin
46
63
 
47
64
  # compute the URL for the image of the data data
@@ -54,12 +71,20 @@ begin
54
71
  image_path = bingImage.image_storage_path image_data[0][:file_name]
55
72
  fallback_image_path = bingImage.image_storage_path image_data[0][:fallback_file_name]
56
73
 
74
+ # path of the downloaded file
75
+ downloaded_data = nil
76
+
57
77
  # try the hi-res image
58
78
  if !image_path.exist?
59
79
 
60
80
  begin
61
81
 
62
82
  bingImage.download_image image_path, image_data[0][:links][:url]
83
+ downloaded_data = {
84
+ :path => image_path,
85
+ :quality => :high,
86
+ :downloaded => Date.today
87
+ }
63
88
  rescue Exception => exception
64
89
  logger.info "I couldn't download the hi-resolution image of the day..."
65
90
  logger.info "I couldn't load " + image_data[0][:links][:url]
@@ -73,12 +98,24 @@ begin
73
98
  begin
74
99
 
75
100
  bingImage.download_image fallback_image_path, image_data[0][:links][:fallback_url]
101
+ downloaded_data = {
102
+ :path => fallback_image_path,
103
+ :quality => :low,
104
+ :downloaded => Date.today
105
+ }
76
106
  rescue Exception => exception
77
107
  logger.info "I couldn't download the low-resolution image of the day..."
78
108
  logger.info "I couldn't load " + image_data[0][:links][:url]
79
109
  end
80
110
  end
81
111
 
112
+ # update our downloaded data
113
+ if downloaded_data
114
+ File.open(downloaded_data_path, "w+") do |file_out|
115
+ file_out.write downloaded_data.to_yaml
116
+ end
117
+ end
118
+
82
119
  # set the wallpaper
83
120
  if image_path.exist?
84
121
 
@@ -88,6 +125,10 @@ begin
88
125
  if options[:gnome]
89
126
  logger.info "Setting background with Gnome"
90
127
  `gsettings set org.gnome.desktop.background picture-uri "file:///#{image_path}"`
128
+ elsif options[:sway]
129
+ logger.info "Setting background with swaymsg"
130
+ `swaymsg output "*" background #{image_path} fill`
131
+ `echo 'exec swaymsg output "*" background #{image_path} fill' > ~/.config/sway/config.d/wallpaper`
91
132
  else
92
133
  logger.info "Setting background with feh"
93
134
  `feh --bg-fill #{image_path}`
@@ -106,6 +147,10 @@ begin
106
147
  if options[:gnome]
107
148
  logger.info "Setting background with Gnome"
108
149
  `gsettings set org.gnome.desktop.background picture-uri "file:///#{fallback_image_path}"`
150
+ elsif options[:sway]
151
+ logger.info "Setting background with swaymsg"
152
+ `swaymsg output "*" background #{fallback_image_path} fill`
153
+ `echo 'exec swaymsg output "*" background #{fallback_image_path} fill' > ~/.config/sway/config.d/wallpaper`
109
154
  else
110
155
  logger.info "Setting background with feh"
111
156
  `feh --bg-fill #{fallback_image_path}`
@@ -124,3 +169,5 @@ rescue Exception => exception
124
169
  logger.error "The problems was: " + exception.message
125
170
  exit 1
126
171
  end
172
+
173
+ exit 0
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["twitch@nervestaple.com"]
11
11
  spec.summary = %q{Sets your wallpaper to Bing's "Image of the Day"}
12
12
  spec.description = %q{This script downloads the "Image of the Day" and then uses Feh or Gnome to set your desktop wallpaper. More information available at https://github.com/cmiles74/bingwallpaper/.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/cmiles74/bingwallpaper"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,8 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "nokogiri", "~> 1.8.2"
21
+ spec.required_ruby_version = '~> 3.0.2'
22
+ spec.add_dependency "nokogiri", "~> 1.12.4"
22
23
  spec.add_dependency "OptionParser", "~> 0.5.1"
23
- spec.add_development_dependency "bundler", "~> 1.6"
24
- spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "bundler", "~> 2.2.27"
25
+ spec.add_development_dependency "irb", "~> 1.3.7"
26
+ spec.add_development_dependency "rake", "~> 13.0.6"
27
+ spec.add_development_dependency "pry", ">= 0.10"
28
+ spec.add_development_dependency "pry-doc", ">= 0.6.0"
29
+ spec.add_development_dependency "method_source", "~> 1.0"
30
+ spec.add_development_dependency "webrick", ">= 1.5.0"
25
31
  end
@@ -45,7 +45,8 @@ module Bingwallpaper
45
45
  # market:: The market to use when fetching
46
46
  # index:: Index of the image to fetch (0 = today)
47
47
  # storage_path:: Path to directory for storing images
48
- def initialize(market = DEFAULT_MARKET, index = DEFAULT_INDEX, storage_path = DEFAULT_STORAGE_PATH)
48
+ def initialize(market = DEFAULT_MARKET, index = DEFAULT_INDEX,
49
+ storage_path = DEFAULT_STORAGE_PATH)
49
50
 
50
51
  @market = market
51
52
  @index = index
@@ -66,7 +67,8 @@ module Bingwallpaper
66
67
  # Returns the data URL for the image of the day.
67
68
  def get_data_url
68
69
 
69
- return build_url(PATH + '?format=' + FORMAT + '&idx=' + @index.to_s + '&n=1' + '&mkt=' + @market)
70
+ return build_url(PATH + '?format=' + FORMAT + '&idx=' + @index.to_s +
71
+ '&n=1' + '&mkt=' + @market)
70
72
  end
71
73
 
72
74
  # Parses the XML data and returns a hash of image information.
@@ -74,13 +76,13 @@ module Bingwallpaper
74
76
  # url:: complete path to the Bing image of the day
75
77
  def parse_xml(url)
76
78
 
77
- doc = Nokogiri::HTML(open(url))
79
+ doc = Nokogiri::HTML(URI.open(url))
78
80
 
79
81
  doc.xpath('//images/image').map do |image|
80
82
 
81
83
  # 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
+ image_path = image.xpath('url').text.sub(
85
+ image.xpath('url').text.rpartition("_").last, '1920x1200.jpg')
84
86
 
85
87
  # store the other path as fallback
86
88
  image_fallback_path = image.xpath('url').text.to_s
@@ -89,12 +91,25 @@ module Bingwallpaper
89
91
  {:links => {:url => build_url(image_path),
90
92
  :fallback_url => build_url(image_fallback_path),
91
93
  :copyright_url => image.xpath('copyrightlink').text},
92
- :file_name => Pathname.new(image_path).basename.to_s,
94
+ :file_name => cleanup_filename(Pathname.new(image_path).basename.to_s),
93
95
  :fallback_file_name => Pathname.new(image_fallback_path).basename.to_s,
94
96
  :copyright => image.xpath('copyright').text}
95
97
  end
96
98
  end
97
99
 
100
+ # Parses out a nice filename from the icky URL.
101
+ #
102
+ # filename:: Filename from the URL
103
+ def cleanup_filename(filename)
104
+ matches = /[A-Za-z0-9_-]+\.jpg/.match(filename)
105
+
106
+ if matches.length > 0
107
+ return matches[0]
108
+ end
109
+
110
+ return filename
111
+ end
112
+
98
113
  # Returns a Pathname with location where the image from the
99
114
  # provided Bing image hash will be stored.
100
115
  #
@@ -114,7 +129,7 @@ module Bingwallpaper
114
129
 
115
130
  # download the hi-res image
116
131
  open(file_path, 'wb') do |file|
117
- file << open(url).read
132
+ file << URI.open(url).read
118
133
  end
119
134
  rescue Exception => exception
120
135
  file_path.delete
@@ -1,3 +1,3 @@
1
1
  module Bingwallpaper
2
- VERSION = "0.6.0"
2
+ VERSION ||= "0.6.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bingwallpaper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - cmiles74
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-22 00:00:00.000000000 Z
11
+ date: 2021-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.2
19
+ version: 1.12.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.8.2
26
+ version: 1.12.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: OptionParser
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,98 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: 2.2.27
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: 2.2.27
55
+ - !ruby/object:Gem::Dependency
56
+ name: irb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.7
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.7
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 13.0.6
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 13.0.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - ">="
60
88
  - !ruby/object:Gem::Version
61
- version: '0'
89
+ version: '0.10'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - ">="
67
95
  - !ruby/object:Gem::Version
68
- version: '0'
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-doc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.6.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.6.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: method_source
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webrick
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 1.5.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 1.5.0
69
139
  description: This script downloads the "Image of the Day" and then uses Feh or Gnome
70
140
  to set your desktop wallpaper. More information available at https://github.com/cmiles74/bingwallpaper/.
71
141
  email:
@@ -76,6 +146,7 @@ extensions: []
76
146
  extra_rdoc_files: []
77
147
  files:
78
148
  - ".gitignore"
149
+ - ".ruby-version"
79
150
  - Gemfile
80
151
  - LICENSE.txt
81
152
  - README.md
@@ -85,28 +156,27 @@ files:
85
156
  - lib/bingwallpaper.rb
86
157
  - lib/bingwallpaper/image.rb
87
158
  - lib/bingwallpaper/version.rb
88
- homepage: ''
159
+ homepage: https://github.com/cmiles74/bingwallpaper
89
160
  licenses:
90
161
  - MIT
91
162
  metadata: {}
92
- post_install_message:
163
+ post_install_message:
93
164
  rdoc_options: []
94
165
  require_paths:
95
166
  - lib
96
167
  required_ruby_version: !ruby/object:Gem::Requirement
97
168
  requirements:
98
- - - ">="
169
+ - - "~>"
99
170
  - !ruby/object:Gem::Version
100
- version: '0'
171
+ version: 3.0.2
101
172
  required_rubygems_version: !ruby/object:Gem::Requirement
102
173
  requirements:
103
174
  - - ">="
104
175
  - !ruby/object:Gem::Version
105
176
  version: '0'
106
177
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.5.2.3
109
- signing_key:
178
+ rubygems_version: 3.2.21
179
+ signing_key:
110
180
  specification_version: 4
111
181
  summary: Sets your wallpaper to Bing's "Image of the Day"
112
182
  test_files: []