bingwallpaper 0.5.5 → 0.5.6

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGJjZDcwY2Y1YzU5MjBjMTAzNTA0YzEwZWY4ZTY4MGYwZTc3NWMzZg==
4
+ YmI3M2ZmNDY2ZmUwMWE1NGI1MjA4MzE4MGYyMjQzYWFhZjczMzNhOA==
5
5
  data.tar.gz: !binary |-
6
- OTQ0NmU5MzU3YTBiMTlmMjA5OThkMzMyYzE5NWE2NmE3NTkwMmMzMA==
6
+ NjIyZTBlODIyODcyMzY2OTgyMWRkMjM2YjQ0MjQwZmEzYjEyOGI5MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTE2MjM1MDM0ZWQ5ZTRmODNkMmNiMzdkM2Q3ZTFmODc2NDM3ZTI0MjliYmZl
10
- MjliYzYxNWM4MTk5MjE2MTk5OTNiZmJmNmQ1OTU5NDlhMWUxNWE0NWM3NTZj
11
- MmU2NmJiMjQ3ZGMyYTVhZTVlM2I1OGY4ZDAyN2RkOWQ0ODMzZTM=
9
+ Yjk4OGZjNTBkZmFlMDU5YmJmMWIzMGM5OWY0MThhM2YwOWU3ZGFiYmQwMGJj
10
+ YWI1NDAzZmM5MjNiNTE1ZDE1ZjhlYmNlODU2OGY0ZTVlYWU0ZTdmN2RmYzc4
11
+ NjRiYmVkMzhmOGI0YmI5MjliZmI2ZDE1NWI5ZjA5YTNjYTlmNmM=
12
12
  data.tar.gz: !binary |-
13
- ZWJkYjE5MDRiMzU2MWZiMjNiYjRiMzk5Yzc0NmZmZGVmOWEyY2MxOGNiYzU2
14
- OGQwOTk0ZTRjMjgzOWQyNmJlMDE3YjQ5YjAwZWQwOWRlMThhMGVhOGVlYzA0
15
- N2QwMTlmODUxY2ZlNjRlZWY3MjdhYWU5YjdmNTUwZGJkNzkxZWI=
13
+ ODBhMDAxZjZiMTRmNDRhOTMwNTgzNTU4NjgzMjM5MTk4NThjYzRhYzEyMmE4
14
+ ZjdmNDMzZDFiNTliY2U1NmE3ZjM4YmFkZjM4ZDM3YTgzYTA3NTJmM2FmOTk2
15
+ MDJmYzgxYTRjMzZhZjZkOWQwODUxNDlhZTY4ODU0MzkwNWFhNDg=
@@ -29,20 +29,29 @@ begin
29
29
  image_path = bingImage.image_storage_path image_data[0][:file_name]
30
30
  fallback_image_path = bingImage.image_storage_path image_data[0][:fallback_file_name]
31
31
 
32
- # only download the wallpaper once
33
- if !(image_path.exist? || fallback_image_path.exist?)
32
+ # try the hi-res image
33
+ if !image_path.exist?
34
34
 
35
35
  begin
36
- # download the image and set the wallpaper
37
- bingImage.download_image image_data[0]
36
+
37
+ bingImage.download_image image_path, image_data[0][:links][:url]
38
38
  rescue Exception => exception
39
- logger.info "Sorry, couldn't download the image of the day. :'("
39
+ logger.info "I couldn't download the hi-resolution image of the day..."
40
+ logger.info "I couldn't load " + image_data[0][:links][:url]
41
+ end
42
+ end
43
+
44
+
45
+ # fallback to the low-res image
46
+ if !image_path.exist? && !fallback_image_path.exist?
47
+
48
+ begin
49
+
50
+ bingImage.download_image fallback_image_path, image_data[0][:links][:fallback_url]
51
+ rescue Exception => exception
52
+ logger.info "I couldn't download the low-resolution image of the day..."
40
53
  logger.info "I couldn't load " + image_data[0][:links][:url]
41
- logger.info image_data[0]
42
- logger.error "The problem was: " + exception.message
43
54
  end
44
- else
45
- logger.info "Today's wallpaper already downloaded. ;-)"
46
55
  end
47
56
 
48
57
  # set the wallpaper
@@ -51,16 +60,18 @@ begin
51
60
  # set the wallpaper
52
61
  logger.info "Wallpaper set to #{image_path}"
53
62
  `feh --bg-fill #{image_path}`
54
- else fallback_image_path.exist?
63
+ elsif fallback_image_path.exist?
55
64
 
56
65
  # set the wallpaper
57
- logger.info "Sorry, only the low-resolution image was available today. :-("
66
+ logger.info "Only the low-resolution image was available today."
58
67
  logger.info "Wallpaper set to #{image_path}"
59
68
  `feh --bg-fill #{fallback_image_path}`
69
+ else
70
+
71
+ logger.info "Sorry, I couldn't download the Bing Image of the Day. :'("
60
72
  end
61
73
  rescue Exception => exception
62
74
  logger.info "Sorry, I couldn't set today's Bing Image of the Day Wallpaper. :'("
63
75
  logger.error "The problems was: " + exception.message
64
- logger.error exception.backtrace
65
76
  exit 1
66
77
  end
@@ -87,7 +87,7 @@ module Bingwallpaper
87
87
 
88
88
  # build our hash of image data
89
89
  {:links => {:url => build_url(image_path),
90
- :fallback_url => image_fallback_path,
90
+ :fallback_url => build_url(image_fallback_path),
91
91
  :copyright_url => image.xpath('copyrightlink').text},
92
92
  :file_name => Pathname.new(image_path).basename.to_s,
93
93
  :fallback_file_name => Pathname.new(image_fallback_path).basename.to_s,
@@ -98,33 +98,27 @@ module Bingwallpaper
98
98
  # Returns a Pathname with location where the image from the
99
99
  # provided Bing image hash will be stored.
100
100
  #
101
- # file_name:: Path to the file storage location
101
+ # file_name:: Path to the file storage location'
102
102
  def image_storage_path(file_name)
103
103
  Pathname.new @storage_path + "/" + file_name
104
104
  end
105
105
 
106
- # Downloads the Bing image from the provided image hash.
106
+ # Downloads the image at the supplied URL and saves it to the
107
+ # specified file.
107
108
  #
108
- # image_date:: Hash of Bing image data
109
- def download_image(image_data)
109
+ # file_path:: Path for the storing image
110
+ # url:: URL to the image to download
111
+ def download_image(file_path, url)
110
112
 
111
113
  begin
112
- open(image_storage_path(image_data[:file_name]), 'wb') do |file|
113
- file << open(image_data[:links][:url]).read
114
- end
115
- rescue Exception => exception
116
-
117
- FileUtils.rm(image_storage_path(image_data[:file_name]))
118
114
 
119
- begin
120
- open(image_storage_path(image_data[:fallback_file_name]), 'wb') do |file|
121
- file << open(image_data[:links][:fallback_url]).read
122
- end
123
- rescue
124
-
125
- FileUtils.rm(image_storage_path(image_data[:fallback_file_name]))
126
- raise exception
115
+ # download the hi-res image
116
+ open(file_path, 'wb') do |file|
117
+ file << open(url).read
127
118
  end
119
+ rescue Exception => exception
120
+ file_path.delete
121
+ raise exception
128
122
  end
129
123
  end
130
124
  end
@@ -1,3 +1,3 @@
1
1
  module Bingwallpaper
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
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.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - cmiles74
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri