cafe_basics_duo 0.1.36 → 0.1.37
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/cafe_basics_duo.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: 0ea656b168468dcf680e00ba06a615aca79d3e3748eb33cfa1bee9f90923c29d
|
4
|
+
data.tar.gz: 6f892b0c8c816bb68af4ffd3aac73f04327c8934d90af79cd77cda7e67718b44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b30ffce6f681d19d52e248866ac695f991f7e39d130dfb329c9d88cc731f23b879a9d99929a8c53675abce0f14f1f9000efacd6a35cb046973dad4030055ae7b
|
7
|
+
data.tar.gz: 27490fd24522ec64ffb0a47c8cbab371c172ed272764e5ac959e1b743c49574b72ddcc5418e29e3789cc6623d9be6d36d4232637a2e6aa85104fa6cce7f6d879
|
data/lib/cafe_basics_duo.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
|
@@ -2031,21 +2032,81 @@ class Wordpress
|
|
2031
2032
|
|
2032
2033
|
|
2033
2034
|
|
2034
|
-
def auto_image
|
2035
|
+
def auto_image(keyword = nil)
|
2036
|
+
keyword ||= @keyword
|
2037
|
+
puts "키워드: #{keyword}"
|
2038
|
+
|
2039
|
+
client = HTTPClient.new
|
2040
|
+
client.default_header = {
|
2041
|
+
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
|
2042
|
+
'(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
|
2043
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
2044
|
+
'Accept-Language' => 'en-US,en;q=0.9',
|
2045
|
+
'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
|
2046
|
+
'X-Requested-With' => 'XMLHttpRequest'
|
2047
|
+
}
|
2048
|
+
|
2049
|
+
retry_count = 0
|
2050
|
+
max_retries = 10
|
2051
|
+
results = []
|
2052
|
+
|
2035
2053
|
begin
|
2036
2054
|
page = rand(1..15)
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2055
|
+
url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
|
2056
|
+
puts "Request URL: #{url}"
|
2057
|
+
res = client.get(url)
|
2058
|
+
|
2059
|
+
unless res.status == 200
|
2060
|
+
puts "HTTP Error: #{res.status}"
|
2061
|
+
raise "HTTP Error"
|
2042
2062
|
end
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2063
|
+
|
2064
|
+
json = JSON.parse(res.body)
|
2065
|
+
results = json['results']
|
2066
|
+
mm = []
|
2067
|
+
|
2068
|
+
results.each do |photo|
|
2069
|
+
full_url = photo.dig('urls', 'full').to_s
|
2070
|
+
regular_url = photo.dig('urls', 'regular').to_s
|
2071
|
+
|
2072
|
+
if full_url.start_with?("https://images.unsplash.com/photo-") &&
|
2073
|
+
regular_url.include?("1080")
|
2074
|
+
mm << full_url
|
2075
|
+
end
|
2076
|
+
end
|
2077
|
+
|
2078
|
+
if mm.empty?
|
2079
|
+
raise "No matching image"
|
2080
|
+
end
|
2081
|
+
|
2082
|
+
selected_url = mm.sample
|
2083
|
+
Down.download(selected_url, destination: "./image/memory.png")
|
2084
|
+
puts "이미지 다운로드 완료: #{selected_url}"
|
2085
|
+
|
2086
|
+
rescue => e
|
2087
|
+
retry_count += 1
|
2088
|
+
puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
|
2089
|
+
sleep(3)
|
2090
|
+
if retry_count < max_retries
|
2048
2091
|
retry
|
2092
|
+
else
|
2093
|
+
puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
|
2094
|
+
|
2095
|
+
if results && !results.empty?
|
2096
|
+
random_photo = results.sample
|
2097
|
+
fallback_url = random_photo.dig('urls', 'full')
|
2098
|
+
if fallback_url
|
2099
|
+
Down.download(fallback_url, destination: "./image/memory.png")
|
2100
|
+
puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
|
2101
|
+
else
|
2102
|
+
puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
|
2103
|
+
color_image
|
2104
|
+
end
|
2105
|
+
else
|
2106
|
+
puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
|
2107
|
+
color_image
|
2108
|
+
end
|
2109
|
+
end
|
2049
2110
|
end
|
2050
2111
|
end
|
2051
2112
|
|