bingwallpaper 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/bingwallpaper +25 -5
- data/lib/bingwallpaper/image.rb +21 -6
- data/lib/bingwallpaper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGJjZDcwY2Y1YzU5MjBjMTAzNTA0YzEwZWY4ZTY4MGYwZTc3NWMzZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTQ0NmU5MzU3YTBiMTlmMjA5OThkMzMyYzE5NWE2NmE3NTkwMmMzMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTE2MjM1MDM0ZWQ5ZTRmODNkMmNiMzdkM2Q3ZTFmODc2NDM3ZTI0MjliYmZl
|
10
|
+
MjliYzYxNWM4MTk5MjE2MTk5OTNiZmJmNmQ1OTU5NDlhMWUxNWE0NWM3NTZj
|
11
|
+
MmU2NmJiMjQ3ZGMyYTVhZTVlM2I1OGY4ZDAyN2RkOWQ0ODMzZTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWJkYjE5MDRiMzU2MWZiMjNiYjRiMzk5Yzc0NmZmZGVmOWEyY2MxOGNiYzU2
|
14
|
+
OGQwOTk0ZTRjMjgzOWQyNmJlMDE3YjQ5YjAwZWQwOWRlMThhMGVhOGVlYzA0
|
15
|
+
N2QwMTlmODUxY2ZlNjRlZWY3MjdhYWU5YjdmNTUwZGJkNzkxZWI=
|
data/bin/bingwallpaper
CHANGED
@@ -26,21 +26,41 @@ begin
|
|
26
26
|
image_data = bingImage.parse_xml data_url
|
27
27
|
|
28
28
|
# decide where we'll save today's image
|
29
|
-
image_path = bingImage.image_storage_path image_data[0]
|
29
|
+
image_path = bingImage.image_storage_path image_data[0][:file_name]
|
30
|
+
fallback_image_path = bingImage.image_storage_path image_data[0][:fallback_file_name]
|
30
31
|
|
31
32
|
# only download the wallpaper once
|
32
|
-
if !image_path.exist?
|
33
|
+
if !(image_path.exist? || fallback_image_path.exist?)
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
begin
|
36
|
+
# download the image and set the wallpaper
|
37
|
+
bingImage.download_image image_data[0]
|
38
|
+
rescue Exception => exception
|
39
|
+
logger.info "Sorry, couldn't download the image of the day. :'("
|
40
|
+
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
|
+
end
|
36
44
|
else
|
37
45
|
logger.info "Today's wallpaper already downloaded. ;-)"
|
38
46
|
end
|
39
47
|
|
40
48
|
# set the wallpaper
|
41
|
-
|
49
|
+
if image_path.exist?
|
50
|
+
|
51
|
+
# set the wallpaper
|
52
|
+
logger.info "Wallpaper set to #{image_path}"
|
53
|
+
`feh --bg-fill #{image_path}`
|
54
|
+
else fallback_image_path.exist?
|
55
|
+
|
56
|
+
# set the wallpaper
|
57
|
+
logger.info "Sorry, only the low-resolution image was available today. :-("
|
58
|
+
logger.info "Wallpaper set to #{image_path}"
|
59
|
+
`feh --bg-fill #{fallback_image_path}`
|
60
|
+
end
|
42
61
|
rescue Exception => exception
|
43
62
|
logger.info "Sorry, I couldn't set today's Bing Image of the Day Wallpaper. :'("
|
44
63
|
logger.error "The problems was: " + exception.message
|
64
|
+
logger.error exception.backtrace
|
45
65
|
exit 1
|
46
66
|
end
|
data/lib/bingwallpaper/image.rb
CHANGED
@@ -82,10 +82,15 @@ module Bingwallpaper
|
|
82
82
|
image_path = image.xpath('url').text.sub(image.xpath('url').text.rpartition("_").
|
83
83
|
last, '1920x1200.jpg')
|
84
84
|
|
85
|
+
# store the other path as fallback
|
86
|
+
image_fallback_path = image.xpath('url').text.to_s
|
87
|
+
|
85
88
|
# build our hash of image data
|
86
89
|
{:links => {:url => build_url(image_path),
|
90
|
+
:fallback_url => image_fallback_path,
|
87
91
|
:copyright_url => image.xpath('copyrightlink').text},
|
88
92
|
:file_name => Pathname.new(image_path).basename.to_s,
|
93
|
+
:fallback_file_name => Pathname.new(image_fallback_path).basename.to_s,
|
89
94
|
:copyright => image.xpath('copyright').text}
|
90
95
|
end
|
91
96
|
end
|
@@ -93,9 +98,9 @@ module Bingwallpaper
|
|
93
98
|
# Returns a Pathname with location where the image from the
|
94
99
|
# provided Bing image hash will be stored.
|
95
100
|
#
|
96
|
-
#
|
97
|
-
def image_storage_path(
|
98
|
-
Pathname.new @storage_path + "/" +
|
101
|
+
# file_name:: Path to the file storage location
|
102
|
+
def image_storage_path(file_name)
|
103
|
+
Pathname.new @storage_path + "/" + file_name
|
99
104
|
end
|
100
105
|
|
101
106
|
# Downloads the Bing image from the provided image hash.
|
@@ -104,12 +109,22 @@ module Bingwallpaper
|
|
104
109
|
def download_image(image_data)
|
105
110
|
|
106
111
|
begin
|
107
|
-
open(image_storage_path(image_data), 'wb') do |file|
|
112
|
+
open(image_storage_path(image_data[:file_name]), 'wb') do |file|
|
108
113
|
file << open(image_data[:links][:url]).read
|
109
114
|
end
|
110
115
|
rescue Exception => exception
|
111
|
-
|
112
|
-
|
116
|
+
|
117
|
+
FileUtils.rm(image_storage_path(image_data[:file_name]))
|
118
|
+
|
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
|
127
|
+
end
|
113
128
|
end
|
114
129
|
end
|
115
130
|
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.
|
4
|
+
version: 0.5.5
|
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-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|