nblog_zon 111.116.779 → 111.117.779
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 +4 -4
- data/lib/nblog_zon.rb +72 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 236e11f30c46482c090215649db157d3719f868b63f9da2122f85365e6d8ce31
|
4
|
+
data.tar.gz: 0abdfd4cae1a308ae9b099601a2acffe18d882e85a0e3ec42f68c52a3d4a3935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a350b2743414ecc315caa68635366ec5b599dfc5586dfb8f8af04b76e88442e86cf17dffefe8d1279151d34186d47c71832222f976063a19a1e9ebf0b805a0
|
7
|
+
data.tar.gz: 64145e27e56ed19e803445de3537499ba75d84f4a780eaeea613b0743a046595b976cf74d44c22f8b71802d6163136f6c7f35ab0392fbc218d189f59afce95a1
|
data/lib/nblog_zon.rb
CHANGED
@@ -17,6 +17,7 @@ require 'cgi'
|
|
17
17
|
require 'digest'
|
18
18
|
require 'auto_click'
|
19
19
|
require 'rainbow/refinement'
|
20
|
+
require 'httpclient'
|
20
21
|
include AutoClickMethods
|
21
22
|
using Rainbow
|
22
23
|
include Glimmer
|
@@ -2153,21 +2154,81 @@ class Wordpress
|
|
2153
2154
|
return @data2
|
2154
2155
|
end
|
2155
2156
|
|
2156
|
-
def auto_image
|
2157
|
+
def auto_image(keyword = nil)
|
2158
|
+
keyword ||= @keyword
|
2159
|
+
puts "키워드: #{keyword}"
|
2160
|
+
|
2161
|
+
client = HTTPClient.new
|
2162
|
+
client.default_header = {
|
2163
|
+
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
|
2164
|
+
'(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
|
2165
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
2166
|
+
'Accept-Language' => 'en-US,en;q=0.9',
|
2167
|
+
'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
|
2168
|
+
'X-Requested-With' => 'XMLHttpRequest'
|
2169
|
+
}
|
2170
|
+
|
2171
|
+
retry_count = 0
|
2172
|
+
max_retries = 10
|
2173
|
+
results = []
|
2174
|
+
|
2157
2175
|
begin
|
2158
2176
|
page = rand(1..15)
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2177
|
+
url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
|
2178
|
+
puts "Request URL: #{url}"
|
2179
|
+
res = client.get(url)
|
2180
|
+
|
2181
|
+
unless res.status == 200
|
2182
|
+
puts "HTTP Error: #{res.status}"
|
2183
|
+
raise "HTTP Error"
|
2164
2184
|
end
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2185
|
+
|
2186
|
+
json = JSON.parse(res.body)
|
2187
|
+
results = json['results']
|
2188
|
+
mm = []
|
2189
|
+
|
2190
|
+
results.each do |photo|
|
2191
|
+
full_url = photo.dig('urls', 'full').to_s
|
2192
|
+
regular_url = photo.dig('urls', 'regular').to_s
|
2193
|
+
|
2194
|
+
if full_url.start_with?("https://images.unsplash.com/photo-") &&
|
2195
|
+
regular_url.include?("1080")
|
2196
|
+
mm << full_url
|
2197
|
+
end
|
2198
|
+
end
|
2199
|
+
|
2200
|
+
if mm.empty?
|
2201
|
+
raise "No matching image"
|
2202
|
+
end
|
2203
|
+
|
2204
|
+
selected_url = mm.sample
|
2205
|
+
Down.download(selected_url, destination: "./image/memory.png")
|
2206
|
+
puts "이미지 다운로드 완료: #{selected_url}"
|
2207
|
+
|
2208
|
+
rescue => e
|
2209
|
+
retry_count += 1
|
2210
|
+
puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
|
2211
|
+
sleep(3)
|
2212
|
+
if retry_count < max_retries
|
2170
2213
|
retry
|
2214
|
+
else
|
2215
|
+
puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
|
2216
|
+
|
2217
|
+
if results && !results.empty?
|
2218
|
+
random_photo = results.sample
|
2219
|
+
fallback_url = random_photo.dig('urls', 'full')
|
2220
|
+
if fallback_url
|
2221
|
+
Down.download(fallback_url, destination: "./image/memory.png")
|
2222
|
+
puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
|
2223
|
+
else
|
2224
|
+
puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
|
2225
|
+
color_image
|
2226
|
+
end
|
2227
|
+
else
|
2228
|
+
puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
|
2229
|
+
color_image
|
2230
|
+
end
|
2231
|
+
end
|
2171
2232
|
end
|
2172
2233
|
end
|
2173
2234
|
|