bingwallpaper 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c7d463413b4ff8a8acb349f42da411983ae8d73
4
- data.tar.gz: 29eb28625a0733fa4fca25f4d2bf071f34780bf9
3
+ metadata.gz: cbe0ff2f5121c0ed61a1409c03032217f3dcd9c1
4
+ data.tar.gz: 7e93502c56083636d162b1bbdf99150991edb065
5
5
  SHA512:
6
- metadata.gz: 889e2ac347079fe55df1d2b1a5a0a5b158dec4a640b92fdb0c3cae7d00cb561b156784efe3d4abd0bc2d441ffaca5f6d51de7ea3fe936cdd245a98500992bd14
7
- data.tar.gz: e542578c1fc8b3698c2d21e4af81812a13c4aac9cdd63d7e1b9fc27b8217a45bca560900a766f45e6bd73ca800094bcc0991714e19f18c3fa15bf67dec80c9cf
6
+ metadata.gz: c159dee737b17aa458bcb3106a95e5e8fb0c224ef62729abb59fb8a1a77e557901e40e748336b1e1c108278e74d66378633ba96f47c37631518a95c5150a4421
7
+ data.tar.gz: 84be0238face2db9f554d6c3f3dcd579b7b7f257e767859c8578b149d2ad1ec297deff4a41bcdfed6287b1c804fe315c6e3fe8abf8141614d92f844102057643
@@ -0,0 +1 @@
1
+ 2.5.3
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
@@ -9,10 +10,10 @@ wallpaper.
9
10
  ## How It Works
10
11
 
11
12
  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.
13
+ simple-minded. It fetches the XML describing today's image, then fetches the
14
+ 1920x1200 sized version if it's available, the lower resolution version if not.
15
+ Lastly, it uses [Feh][1] or Gnome to set the wallpaper for your environment.
16
+ I've tested it in [i3][2] and Gnome 3.14.2 and nowhere else.
16
17
 
17
18
  ## Using the Script
18
19
 
@@ -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)
@@ -42,6 +43,18 @@ end.parse!
42
43
  # create an instance and set the wallpaper
43
44
  bingImage = Bingwallpaper::Image.new
44
45
 
46
+ # bail out if we've already downloaded today's image
47
+ downloaded_data_path = bingImage.image_storage_path ".bingwallpaper"
48
+ if File.exist? downloaded_data_path
49
+
50
+ downloaded_data = YAML.load_file downloaded_data_path
51
+ if downloaded_data[:downloaded] == Date.today
52
+
53
+ logger.info "Image of the day already downloaded and set"
54
+ exit 0
55
+ end
56
+ end
57
+
45
58
  begin
46
59
 
47
60
  # compute the URL for the image of the data data
@@ -54,12 +67,20 @@ begin
54
67
  image_path = bingImage.image_storage_path image_data[0][:file_name]
55
68
  fallback_image_path = bingImage.image_storage_path image_data[0][:fallback_file_name]
56
69
 
70
+ # path of the downloaded file
71
+ downloaded_data = nil
72
+
57
73
  # try the hi-res image
58
74
  if !image_path.exist?
59
75
 
60
76
  begin
61
77
 
62
78
  bingImage.download_image image_path, image_data[0][:links][:url]
79
+ downloaded_data = {
80
+ :path => image_path,
81
+ :quality => :high,
82
+ :downloaded => Date.today
83
+ }
63
84
  rescue Exception => exception
64
85
  logger.info "I couldn't download the hi-resolution image of the day..."
65
86
  logger.info "I couldn't load " + image_data[0][:links][:url]
@@ -73,12 +94,24 @@ begin
73
94
  begin
74
95
 
75
96
  bingImage.download_image fallback_image_path, image_data[0][:links][:fallback_url]
97
+ downloaded_data = {
98
+ :path => fallback_image_path,
99
+ :quality => :low,
100
+ :downloaded => Date.today
101
+ }
76
102
  rescue Exception => exception
77
103
  logger.info "I couldn't download the low-resolution image of the day..."
78
104
  logger.info "I couldn't load " + image_data[0][:links][:url]
79
105
  end
80
106
  end
81
107
 
108
+ # update our downloaded data
109
+ if downloaded_data
110
+ File.open(downloaded_data_path, "w+") do |file_out|
111
+ file_out.write downloaded_data.to_yaml
112
+ end
113
+ end
114
+
82
115
  # set the wallpaper
83
116
  if image_path.exist?
84
117
 
@@ -124,3 +157,5 @@ rescue Exception => exception
124
157
  logger.error "The problems was: " + exception.message
125
158
  exit 1
126
159
  end
160
+
161
+ exit 0
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "OptionParser", "~> 0.5.1"
23
23
  spec.add_development_dependency "bundler", "~> 1.6"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "pry", "~> 0.10.3"
26
+ spec.add_development_dependency "pry-doc", ">= 0.8.0"
27
+ spec.add_development_dependency "method_source", ">= 0.8.2"
25
28
  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.
@@ -79,8 +81,8 @@ module Bingwallpaper
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
  #
@@ -1,3 +1,3 @@
1
1
  module Bingwallpaper
2
- VERSION = "0.6.0"
2
+ VERSION ||= "0.6.1"
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cmiles74
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-22 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -66,6 +66,48 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-doc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.8.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.8.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: method_source
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.8.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.8.2
69
111
  description: This script downloads the "Image of the Day" and then uses Feh or Gnome
70
112
  to set your desktop wallpaper. More information available at https://github.com/cmiles74/bingwallpaper/.
71
113
  email:
@@ -76,6 +118,7 @@ extensions: []
76
118
  extra_rdoc_files: []
77
119
  files:
78
120
  - ".gitignore"
121
+ - ".ruby-version"
79
122
  - Gemfile
80
123
  - LICENSE.txt
81
124
  - README.md
@@ -105,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
148
  version: '0'
106
149
  requirements: []
107
150
  rubyforge_project:
108
- rubygems_version: 2.5.2.3
151
+ rubygems_version: 2.4.8
109
152
  signing_key:
110
153
  specification_version: 4
111
154
  summary: Sets your wallpaper to Bing's "Image of the Day"