cafe_buy_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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cafe_buy_duo.rb +72 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 248ffb1cd2911811afb751290979b2a39f537fc0125ea6cd9bc2616b247c2a9e
4
- data.tar.gz: 72c940097156c9ac66452db9aad84ce7048c5b4c7d06ae9b87c44e519a0ba0ac
3
+ metadata.gz: 5d1fbf0831bc2c239808b970689f328a8bcce69f7704e1494f4c2220a3c7bec8
4
+ data.tar.gz: 317cac4913eb831b70d4701dd2382963c80e772192f9be163e71b51482b527b2
5
5
  SHA512:
6
- metadata.gz: 4dc056c50f0ce595bef3897910bc2b7a3afd4c3fdac1a73147cfc139e6af8e80a05300ca6f1a11708f4963729a06482a19ccb3e24a8e1c27b623e6ba4cafc5ef
7
- data.tar.gz: 603e100097a0412a567cbd6431fa68cf9cee74ef8a6866f4017015b33e622cbddd92a2bd2342a32715a94a719ab6634cce89a088d3511bde40c32c2e0c78faac
6
+ metadata.gz: bec8d0d0604b46ff383ae9475fae59ad4b4c0381a352ce6529e2f918519e44cd166b59fb7eabb3c77229875d7c256639317bbafb3957db772dcf23edd039a204
7
+ data.tar.gz: 0ee0dbcb27a000b17792a117d58d56d97bc5b524e094252991e80b110656aa31a1b25f545cf0650283d82930cce01ebc6ed000567237735a1abb44c8d96b3fbc
data/lib/cafe_buy_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
@@ -2369,21 +2370,81 @@ class Wordpress
2369
2370
 
2370
2371
 
2371
2372
 
2372
- def auto_image
2373
+ def auto_image(keyword = nil)
2374
+ keyword ||= @keyword
2375
+ puts "키워드: #{keyword}"
2376
+
2377
+ client = HTTPClient.new
2378
+ client.default_header = {
2379
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
2380
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
2381
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
2382
+ 'Accept-Language' => 'en-US,en;q=0.9',
2383
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
2384
+ 'X-Requested-With' => 'XMLHttpRequest'
2385
+ }
2386
+
2387
+ retry_count = 0
2388
+ max_retries = 10
2389
+ results = []
2390
+
2373
2391
  begin
2374
2392
  page = rand(1..15)
2375
- http = HTTP.get('https://unsplash.com/napi/photos?per_page=12&page='+page.to_s)
2376
- json = JSON.parse(http.to_s)
2377
- mm = Array.new
2378
- json.each do |i|
2379
- mm << i['urls']['full']
2393
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
2394
+ puts "Request URL: #{url}"
2395
+ res = client.get(url)
2396
+
2397
+ unless res.status == 200
2398
+ puts "HTTP Error: #{res.status}"
2399
+ raise "HTTP Error"
2380
2400
  end
2381
- url = mm.sample
2382
- Down.download(url, destination: "./image/memory.png")
2383
- rescue
2384
- puts 'auto_image 일시적 error 5초후 제시도...'
2385
- sleep(5)
2401
+
2402
+ json = JSON.parse(res.body)
2403
+ results = json['results']
2404
+ mm = []
2405
+
2406
+ results.each do |photo|
2407
+ full_url = photo.dig('urls', 'full').to_s
2408
+ regular_url = photo.dig('urls', 'regular').to_s
2409
+
2410
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
2411
+ regular_url.include?("1080")
2412
+ mm << full_url
2413
+ end
2414
+ end
2415
+
2416
+ if mm.empty?
2417
+ raise "No matching image"
2418
+ end
2419
+
2420
+ selected_url = mm.sample
2421
+ Down.download(selected_url, destination: "./image/memory.png")
2422
+ puts "이미지 다운로드 완료: #{selected_url}"
2423
+
2424
+ rescue => e
2425
+ retry_count += 1
2426
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
2427
+ sleep(3)
2428
+ if retry_count < max_retries
2386
2429
  retry
2430
+ else
2431
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
2432
+
2433
+ if results && !results.empty?
2434
+ random_photo = results.sample
2435
+ fallback_url = random_photo.dig('urls', 'full')
2436
+ if fallback_url
2437
+ Down.download(fallback_url, destination: "./image/memory.png")
2438
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
2439
+ else
2440
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
2441
+ color_image
2442
+ end
2443
+ else
2444
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
2445
+ color_image
2446
+ end
2447
+ end
2387
2448
  end
2388
2449
  end
2389
2450
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cafe_buy_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon