cafe_buy_duo 0.1.35 → 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 +125 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f22d70ec27de58f57890da03c82c3a5e07aa6c6b9bfd999825752a79bd3e0d7
4
- data.tar.gz: f6809689b474d58d6f2de67fc0e159594afe6d07c5baddb025e7c6352b7172a1
3
+ metadata.gz: 5d1fbf0831bc2c239808b970689f328a8bcce69f7704e1494f4c2220a3c7bec8
4
+ data.tar.gz: 317cac4913eb831b70d4701dd2382963c80e772192f9be163e71b51482b527b2
5
5
  SHA512:
6
- metadata.gz: 57b3cda29bcbbb9aa907fc1efdb90a543868724f3c65efa4328ea05278962fea81a02db64a9553bece40a935c6ceb02570849ec4d4e851ff507a4ff198f21822
7
- data.tar.gz: 4164121816e66bbbfa0bd863716df0ca1b7376cbe928bd5ee6a0808bba5d364cb3307b7876328210d9bcf40e4fda5bafbd5994dceec00719564184a58df2a83f
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
 
@@ -2523,18 +2584,40 @@ class Wordpress
2523
2584
  image_filter()
2524
2585
  end
2525
2586
 
2526
- insert_image_text1 = ''
2527
- insert_image_text2 = ''
2528
2587
  if @data['이미지설정']['글자삽입1'].checked?
2529
- insert_image_text1 = @data['이미지설정']['이미지글자1'].sample
2588
+ if @data['이미지설정']['이미지글자1'].length == 0
2589
+ image_text_path1 = ''
2590
+ else
2591
+ if @data['이미지설정']['글자랜덤'].checked?
2592
+ image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2593
+ else
2594
+ image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2595
+ @image_text_soon1 += 1
2596
+ if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2597
+ @image_text_soon1 = 0
2598
+ end
2599
+ end
2600
+ end
2530
2601
  end
2531
2602
 
2532
2603
  if @data['이미지설정']['글자삽입2'].checked?
2533
- insert_image_text2 = @data['이미지설정']['이미지글자2'].sample
2604
+ if @data['이미지설정']['이미지글자2'].length == 0
2605
+ image_text_path2 = ''
2606
+ else
2607
+ if @data['이미지설정']['글자랜덤'].checked?
2608
+ image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2609
+ else
2610
+ image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2611
+ @image_text_soon2 += 1
2612
+ if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2613
+ @image_text_soon2 = 0
2614
+ end
2615
+ end
2616
+ end
2534
2617
  end
2535
-
2618
+
2536
2619
  if @data['이미지설정']['글자삽입1'].checked? or @data['이미지설정']['글자삽입2'].checked?
2537
- image_text(insert_image_text1, insert_image_text2)
2620
+ image_text(image_text_path1, image_text_path2)
2538
2621
  end
2539
2622
 
2540
2623
  if @data['이미지설정']['테두리사용'].checked?
@@ -2598,6 +2681,8 @@ class Wordpress
2598
2681
  title_soon = 0
2599
2682
  keyword_soon = 0
2600
2683
  content_soon = 0
2684
+ @image_text_soon1 = 0
2685
+ @image_text_soon2 = 0
2601
2686
  @my_ip = 'init'
2602
2687
  @image_counter = 0
2603
2688
  @inumber2 = 0
@@ -4885,9 +4970,30 @@ class Wordpress
4885
4970
  top 1
4886
4971
  left 6
4887
4972
  }
4888
- @data['이미지설정']['필터사용'] = checkbox('필터사용(색상 사진 적용불가)'){
4973
+ @data['이미지설정']['글자순서'] = checkbox('글자 리스트 순서대로 사용'){
4889
4974
  top 2
4890
4975
  left 0
4976
+ on_toggled{
4977
+ if @data['이미지설정']['글자순서'].checked?
4978
+ @data['이미지설정']['글자랜덤'].checked = false
4979
+ end
4980
+ }
4981
+ }
4982
+
4983
+ @data['이미지설정']['글자랜덤'] = checkbox('글자 리스트 랜덤으로 사용'){
4984
+ top 2
4985
+ left 1
4986
+ on_toggled{
4987
+ if @data['이미지설정']['글자랜덤'].checked?
4988
+ @data['이미지설정']['글자순서'].checked = false
4989
+ end
4990
+ }
4991
+ }
4992
+
4993
+
4994
+ @data['이미지설정']['필터사용'] = checkbox('필터사용(색상 사진 적용불가)'){
4995
+ top 2
4996
+ left 2
4891
4997
  }
4892
4998
  @data['이미지설정']['테두리사용'] = checkbox('테두리 사용'){
4893
4999
  top 3
@@ -6010,6 +6116,7 @@ class Wordpress
6010
6116
  @data['포스트설정']['자동출처 사용'].checked = false
6011
6117
  @data['포스트설정']['CCL사용'].checked = false
6012
6118
  @data['포스트설정']['인용구랜덤'].checked = true
6119
+ @data['이미지설정']['글자순서'].checked = true
6013
6120
 
6014
6121
  }.show
6015
6122
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cafe_buy_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.35
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-22 00:00:00.000000000 Z
10
+ date: 2025-05-23 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: File to Clipboard gem
13
13
  email: mymin26@naver.com