cafe_buy_duo 0.1.36 → 0.1.39

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 +232 -63
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 248ffb1cd2911811afb751290979b2a39f537fc0125ea6cd9bc2616b247c2a9e
4
- data.tar.gz: 72c940097156c9ac66452db9aad84ce7048c5b4c7d06ae9b87c44e519a0ba0ac
3
+ metadata.gz: fb2ff3d45a7a4741dc8f2832caf344eef733f7091f407596be679349b70bcd3a
4
+ data.tar.gz: bfeece7521759fc56fd83ae41992f66239e182859ac8109afba02f44eee2391f
5
5
  SHA512:
6
- metadata.gz: 4dc056c50f0ce595bef3897910bc2b7a3afd4c3fdac1a73147cfc139e6af8e80a05300ca6f1a11708f4963729a06482a19ccb3e24a8e1c27b623e6ba4cafc5ef
7
- data.tar.gz: 603e100097a0412a567cbd6431fa68cf9cee74ef8a6866f4017015b33e622cbddd92a2bd2342a32715a94a719ab6634cce89a088d3511bde40c32c2e0c78faac
6
+ metadata.gz: 9668239becff0fd5b4bb3552dd891f2f271f1591c985a842fad075c15622901f8cb7ae3df97d25727febd712eab8cf3aa62e310cab6d1fb715c749a3381a972c
7
+ data.tar.gz: f1b110ee2f7f7a8d4c2c8900baf684dae5655173a1059b929b70afe945a51148c01e318884d75e99cf9505aa830a1b1d20e956e4428eabe9f86523ca37edee2f
data/lib/cafe_buy_duo.rb CHANGED
@@ -17,6 +17,8 @@ require 'cgi'
17
17
  require 'digest'
18
18
  require 'auto_click'
19
19
  require 'rainbow/refinement'
20
+ require 'httpclient'
21
+ require 'win32ole'
20
22
  include AutoClickMethods
21
23
  using Rainbow
22
24
  include Glimmer
@@ -241,8 +243,38 @@ end
241
243
  class Naver
242
244
  def initialize
243
245
  @seed = 1
246
+ kill_selenium_chrome #기존 창 모두 닫는 명령
247
+ sleep(1)
244
248
  end
245
249
 
250
+ def kill_selenium_chrome #기존 창 모두 닫는 코드
251
+ wmi = WIN32OLE.connect("winmgmts://")
252
+ chrome_procs = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'chrome.exe'")
253
+
254
+ chrome_procs.each do |proc|
255
+ cmd = proc.CommandLine
256
+ if cmd && cmd.include?("user-data-dir=C:/naver_cookie")
257
+ puts "→ 크롬 창 초기화: PID #{proc.ProcessId}"
258
+ begin
259
+ proc.Terminate
260
+ rescue
261
+ #puts "→ 이미 종료된 프로세스: #{proc.ProcessId}"
262
+ end
263
+ end
264
+ end
265
+
266
+ # chromedriver도 같이 종료
267
+ chromedrivers = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'chromedriver.exe'")
268
+ chromedrivers.each do |proc|
269
+ puts "→ 크롬 창 초기화: PID #{proc.ProcessId}"
270
+ begin
271
+ proc.Terminate
272
+ rescue
273
+ #puts "→ 이미 종료된 chromedriver: #{proc.ProcessId}"
274
+ end
275
+ end
276
+ end
277
+
246
278
 
247
279
  def chrome_setup(user_id, proxy)
248
280
  naver_cookie_dir = "C:/naver_cookie"
@@ -2369,21 +2401,81 @@ class Wordpress
2369
2401
 
2370
2402
 
2371
2403
 
2372
- def auto_image
2404
+ def auto_image(keyword = nil)
2405
+ keyword ||= @keyword
2406
+ puts "키워드: #{keyword}"
2407
+
2408
+ client = HTTPClient.new
2409
+ client.default_header = {
2410
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
2411
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
2412
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
2413
+ 'Accept-Language' => 'en-US,en;q=0.9',
2414
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
2415
+ 'X-Requested-With' => 'XMLHttpRequest'
2416
+ }
2417
+
2418
+ retry_count = 0
2419
+ max_retries = 10
2420
+ results = []
2421
+
2373
2422
  begin
2374
2423
  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']
2424
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
2425
+ puts "Request URL: #{url}"
2426
+ res = client.get(url)
2427
+
2428
+ unless res.status == 200
2429
+ puts "HTTP Error: #{res.status}"
2430
+ raise "HTTP Error"
2380
2431
  end
2381
- url = mm.sample
2382
- Down.download(url, destination: "./image/memory.png")
2383
- rescue
2384
- puts 'auto_image 일시적 error 5초후 제시도...'
2385
- sleep(5)
2432
+
2433
+ json = JSON.parse(res.body)
2434
+ results = json['results']
2435
+ mm = []
2436
+
2437
+ results.each do |photo|
2438
+ full_url = photo.dig('urls', 'full').to_s
2439
+ regular_url = photo.dig('urls', 'regular').to_s
2440
+
2441
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
2442
+ regular_url.include?("1080")
2443
+ mm << full_url
2444
+ end
2445
+ end
2446
+
2447
+ if mm.empty?
2448
+ raise "No matching image"
2449
+ end
2450
+
2451
+ selected_url = mm.sample
2452
+ Down.download(selected_url, destination: "./image/memory.png")
2453
+ puts "이미지 다운로드 완료: #{selected_url}"
2454
+
2455
+ rescue => e
2456
+ retry_count += 1
2457
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
2458
+ sleep(3)
2459
+ if retry_count < max_retries
2386
2460
  retry
2461
+ else
2462
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
2463
+
2464
+ if results && !results.empty?
2465
+ random_photo = results.sample
2466
+ fallback_url = random_photo.dig('urls', 'full')
2467
+ if fallback_url
2468
+ Down.download(fallback_url, destination: "./image/memory.png")
2469
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
2470
+ else
2471
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
2472
+ color_image
2473
+ end
2474
+ else
2475
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
2476
+ color_image
2477
+ end
2478
+ end
2387
2479
  end
2388
2480
  end
2389
2481
 
@@ -2422,52 +2514,106 @@ class Wordpress
2422
2514
  img = Magick::Image.read('./image/memory.png').first
2423
2515
  width = img.columns
2424
2516
  height = img.rows
2425
- begin
2426
- if @data['image_type'][0].checked? or @data['image_type'][2].checked?
2427
- img.resize!(w, w*(height.to_f/width.to_f))
2428
- else
2429
- img.resize!(w, w)
2517
+
2518
+ # '원본' 선택된 경우, 리사이징을 하지 않고 원본 이미지를 그대로 반환
2519
+ if w == 'original'
2520
+ return img # 원본 이미지 그대로 반환
2521
+ else
2522
+ begin
2523
+ if @data['image_type'][0].checked? or @data['image_type'][2].checked?
2524
+ # 비율을 맞추어 리사이징
2525
+ img.resize!(w, w * (height.to_f / width.to_f))
2526
+ else
2527
+ # 정사각형으로 리사이징
2528
+ img.resize!(w, w)
2529
+ end
2530
+ rescue
2531
+ img.resize!(w, w) # 예외 처리 시에도 리사이징
2430
2532
  end
2431
- rescue
2432
- img.resize!(w, w)
2433
2533
  end
2534
+
2535
+ # 리사이징된 이미지 저장
2434
2536
  img.write('./image/memory.png')
2435
2537
  end
2436
2538
 
2539
+ def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
2540
+ size = initial_size
2541
+ draw.font = font_path
2542
+
2543
+ loop do
2544
+ draw.pointsize = size
2545
+ words = text.chars # 글자 단위로 자름 (한국어 기준)
2546
+ lines = []
2547
+ line = ""
2548
+
2549
+ words.each do |char|
2550
+ test_line = line + char
2551
+ metrics = draw.get_type_metrics(test_line)
2552
+ if metrics.width > max_width
2553
+ lines << line
2554
+ line = char
2555
+ else
2556
+ line = test_line
2557
+ end
2558
+ end
2559
+ lines << line unless line.empty?
2560
+
2561
+ line_height = draw.get_type_metrics("가").height
2562
+ total_height = line_height * lines.size
2563
+
2564
+ # 세로 초과 안 하면 성공
2565
+ if total_height <= max_height || size <= 10
2566
+ return [lines.join("\n"), size]
2567
+ else
2568
+ size -= 2
2569
+ end
2570
+ end
2571
+ end
2572
+
2573
+
2437
2574
  def image_text(text1, text2)
2438
2575
  begin
2439
2576
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
2440
- font = Dir.entries('./fonts')
2441
- img = Magick::Image.read('./image/memory.png').first
2442
- text = Magick::Draw.new
2577
+ font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
2578
+ font2 = './fonts/' + font_files.sample
2443
2579
  color2 = color.sample
2444
- font2 = './fonts/'+font.sample
2445
- message = text1.to_s+"\n"+text2.to_s
2580
+
2581
+ img = Magick::Image.read('./image/memory.png').first
2582
+ draw = Magick::Draw.new
2583
+
2584
+ raw_message = "#{text1}\n#{text2}".strip
2585
+ max_width = img.columns * 0.85
2586
+ max_height = img.rows * 0.6
2587
+
2446
2588
  begin
2447
2589
  size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
2448
2590
  rescue
2449
2591
  size = 30
2450
2592
  end
2593
+
2594
+ wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
2595
+
2451
2596
  if @data['이미지설정']['글자그림자'].checked?
2452
- img.annotate(text, 0,0, +3,+3, message) do
2453
- text.gravity = Magick::CenterGravity
2454
- text.pointsize = size
2455
- text.fill = '#000000'
2456
- text.font = font2
2597
+ img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
2598
+ draw.gravity = Magick::CenterGravity
2599
+ draw.pointsize = adjusted_size
2600
+ draw.fill = '#000000'
2601
+ draw.font = font2
2457
2602
  end
2458
2603
  end
2459
-
2460
- img.annotate(text, 0,0,0,0, message) do
2461
- text.gravity = Magick::CenterGravity
2462
- text.pointsize = size
2604
+
2605
+ draw2 = Magick::Draw.new
2606
+ img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
2607
+ draw2.gravity = Magick::CenterGravity
2608
+ draw2.pointsize = adjusted_size
2609
+ draw2.fill = color2
2610
+ draw2.font = font2
2463
2611
  if @data['이미지설정']['글자테두리'].checked?
2464
- text.stroke_width = 2
2465
- text.stroke = '#000000'
2612
+ draw2.stroke_width = 2
2613
+ draw2.stroke = '#000000'
2466
2614
  end
2467
- text.fill = color2
2468
- text.font = font2
2469
2615
  end
2470
-
2616
+
2471
2617
  img.write('./image/memory.png')
2472
2618
  rescue
2473
2619
  puts '이미지 폰트 불러오기 오류 재시도...'
@@ -2501,23 +2647,30 @@ class Wordpress
2501
2647
  else
2502
2648
  auto_image()
2503
2649
  end
2504
-
2505
- image_size = [480,740,650,550,480]
2650
+
2651
+ # '원본'을 포함한 이미지 크기 옵션 추가
2652
+ image_size = [480, 740, 650, 550, 480, 'original']
2506
2653
  size = 0
2507
- for n in 0..4
2654
+
2655
+ for n in 0..5 # 0부터 5까지 반복, '원본' 옵션까지 포함
2508
2656
  if @data['image_size'][n].checked?
2509
- if n == 0
2510
- size = image_size.sample
2657
+ if n == 5 # '원본'이 선택되었을 경우
2658
+ size = 'original'
2659
+ elsif n == 0
2660
+ size = image_size.sample # 랜덤 선택
2511
2661
  else
2512
2662
  size = image_size[n]
2513
2663
  end
2514
2664
  end
2515
2665
  end
2666
+
2667
+ # '원본'이 선택되지 않았다면 기본 값 설정
2516
2668
  if size == 0
2517
2669
  size = 480
2518
2670
  end
2671
+
2672
+ change_image_size(size) # 크기 변경 함수 호출
2519
2673
 
2520
- change_image_size(size)
2521
2674
 
2522
2675
  if @data['이미지설정']['필터사용'].checked?
2523
2676
  image_filter()
@@ -2525,33 +2678,33 @@ class Wordpress
2525
2678
 
2526
2679
  if @data['이미지설정']['글자삽입1'].checked?
2527
2680
  if @data['이미지설정']['이미지글자1'].length == 0
2528
- image_text_path1 = ''
2681
+ image_text_path1 = ''
2529
2682
  else
2530
- if @data['이미지설정']['글자랜덤'].checked?
2531
- image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2532
- else
2533
- image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2534
- @image_text_soon1 += 1
2535
- if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2536
- @image_text_soon1 = 0
2537
- end
2538
- end
2683
+ if @data['이미지설정']['글자랜덤'].checked?
2684
+ image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2685
+ else
2686
+ image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2687
+ @image_text_soon1 += 1
2688
+ if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2689
+ @image_text_soon1 = 0
2690
+ end
2691
+ end
2539
2692
  end
2540
2693
  end
2541
2694
 
2542
2695
  if @data['이미지설정']['글자삽입2'].checked?
2543
2696
  if @data['이미지설정']['이미지글자2'].length == 0
2544
- image_text_path2 = ''
2697
+ image_text_path2 = ''
2545
2698
  else
2546
- if @data['이미지설정']['글자랜덤'].checked?
2547
- image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2548
- else
2549
- image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2550
- @image_text_soon2 += 1
2551
- if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2552
- @image_text_soon2 = 0
2553
- end
2554
- end
2699
+ if @data['이미지설정']['글자랜덤'].checked?
2700
+ image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2701
+ else
2702
+ image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2703
+ @image_text_soon2 += 1
2704
+ if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2705
+ @image_text_soon2 = 0
2706
+ end
2707
+ end
2555
2708
  end
2556
2709
  end
2557
2710
 
@@ -4968,6 +5121,7 @@ class Wordpress
4968
5121
  @data['image_size'][2].checked = false
4969
5122
  @data['image_size'][3].checked = false
4970
5123
  @data['image_size'][4].checked = false
5124
+ @data['image_size'][5].checked = false
4971
5125
  end
4972
5126
  }
4973
5127
  }
@@ -4978,6 +5132,7 @@ class Wordpress
4978
5132
  @data['image_size'][2].checked = false
4979
5133
  @data['image_size'][3].checked = false
4980
5134
  @data['image_size'][4].checked = false
5135
+ @data['image_size'][5].checked = false
4981
5136
  end
4982
5137
  }
4983
5138
  }
@@ -4988,6 +5143,7 @@ class Wordpress
4988
5143
  @data['image_size'][0].checked = false
4989
5144
  @data['image_size'][3].checked = false
4990
5145
  @data['image_size'][4].checked = false
5146
+ @data['image_size'][5].checked = false
4991
5147
  end
4992
5148
  }
4993
5149
  }
@@ -4998,6 +5154,7 @@ class Wordpress
4998
5154
  @data['image_size'][2].checked = false
4999
5155
  @data['image_size'][0].checked = false
5000
5156
  @data['image_size'][4].checked = false
5157
+ @data['image_size'][5].checked = false
5001
5158
  end
5002
5159
  }
5003
5160
  }
@@ -5008,6 +5165,18 @@ class Wordpress
5008
5165
  @data['image_size'][2].checked = false
5009
5166
  @data['image_size'][3].checked = false
5010
5167
  @data['image_size'][0].checked = false
5168
+ @data['image_size'][5].checked = false
5169
+ end
5170
+ }
5171
+ }
5172
+ @data['image_size'][5] = checkbox('원본 px'){
5173
+ on_toggled{
5174
+ if @data['image_size'][5].checked?
5175
+ @data['image_size'][1].checked = false
5176
+ @data['image_size'][2].checked = false
5177
+ @data['image_size'][3].checked = false
5178
+ @data['image_size'][0].checked = false
5179
+ @data['image_size'][4].checked = false
5011
5180
  end
5012
5181
  }
5013
5182
  }
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.36
4
+ version: 0.1.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-23 00:00:00.000000000 Z
10
+ date: 2025-05-29 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: File to Clipboard gem
13
13
  email: mymin26@naver.com