cafe_buy 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.
- checksums.yaml +4 -4
- data/lib/cafe_buy.rb +232 -63
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e3f6e7ff4507602e98f00a16611632c63ccffd7ee933f19b9343af7c7b21228
|
4
|
+
data.tar.gz: 6fd0fdc57626f0617dc02f75e741db2f6e42d178fbce6733fa203dc503b1c80f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 591fd98593f42a8f0789a244d89536a898657943e950dc4c05b0fd7bb592929377da1205385c7fbb631db2e71066c5f2aadff3605281cf26aa2fbfab34d17291
|
7
|
+
data.tar.gz: 980f2722c2428dd183d2489ad7216ed2ce1e8e3cbc3f3f0986e076728e7311ef689d8042c60b430068caeb7362e18b1cef218b12aae0b008a192fb0ce56af0b3
|
data/lib/cafe_buy.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"
|
@@ -2301,21 +2333,81 @@ class Wordpress
|
|
2301
2333
|
|
2302
2334
|
|
2303
2335
|
|
2304
|
-
def auto_image
|
2336
|
+
def auto_image(keyword = nil)
|
2337
|
+
keyword ||= @keyword
|
2338
|
+
puts "키워드: #{keyword}"
|
2339
|
+
|
2340
|
+
client = HTTPClient.new
|
2341
|
+
client.default_header = {
|
2342
|
+
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
|
2343
|
+
'(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
|
2344
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
2345
|
+
'Accept-Language' => 'en-US,en;q=0.9',
|
2346
|
+
'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
|
2347
|
+
'X-Requested-With' => 'XMLHttpRequest'
|
2348
|
+
}
|
2349
|
+
|
2350
|
+
retry_count = 0
|
2351
|
+
max_retries = 10
|
2352
|
+
results = []
|
2353
|
+
|
2305
2354
|
begin
|
2306
2355
|
page = rand(1..15)
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2356
|
+
url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
|
2357
|
+
puts "Request URL: #{url}"
|
2358
|
+
res = client.get(url)
|
2359
|
+
|
2360
|
+
unless res.status == 200
|
2361
|
+
puts "HTTP Error: #{res.status}"
|
2362
|
+
raise "HTTP Error"
|
2312
2363
|
end
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
2364
|
+
|
2365
|
+
json = JSON.parse(res.body)
|
2366
|
+
results = json['results']
|
2367
|
+
mm = []
|
2368
|
+
|
2369
|
+
results.each do |photo|
|
2370
|
+
full_url = photo.dig('urls', 'full').to_s
|
2371
|
+
regular_url = photo.dig('urls', 'regular').to_s
|
2372
|
+
|
2373
|
+
if full_url.start_with?("https://images.unsplash.com/photo-") &&
|
2374
|
+
regular_url.include?("1080")
|
2375
|
+
mm << full_url
|
2376
|
+
end
|
2377
|
+
end
|
2378
|
+
|
2379
|
+
if mm.empty?
|
2380
|
+
raise "No matching image"
|
2381
|
+
end
|
2382
|
+
|
2383
|
+
selected_url = mm.sample
|
2384
|
+
Down.download(selected_url, destination: "./image/memory.png")
|
2385
|
+
puts "이미지 다운로드 완료: #{selected_url}"
|
2386
|
+
|
2387
|
+
rescue => e
|
2388
|
+
retry_count += 1
|
2389
|
+
puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
|
2390
|
+
sleep(3)
|
2391
|
+
if retry_count < max_retries
|
2318
2392
|
retry
|
2393
|
+
else
|
2394
|
+
puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
|
2395
|
+
|
2396
|
+
if results && !results.empty?
|
2397
|
+
random_photo = results.sample
|
2398
|
+
fallback_url = random_photo.dig('urls', 'full')
|
2399
|
+
if fallback_url
|
2400
|
+
Down.download(fallback_url, destination: "./image/memory.png")
|
2401
|
+
puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
|
2402
|
+
else
|
2403
|
+
puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
|
2404
|
+
color_image
|
2405
|
+
end
|
2406
|
+
else
|
2407
|
+
puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
|
2408
|
+
color_image
|
2409
|
+
end
|
2410
|
+
end
|
2319
2411
|
end
|
2320
2412
|
end
|
2321
2413
|
|
@@ -2354,52 +2446,106 @@ class Wordpress
|
|
2354
2446
|
img = Magick::Image.read('./image/memory.png').first
|
2355
2447
|
width = img.columns
|
2356
2448
|
height = img.rows
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2449
|
+
|
2450
|
+
# '원본'이 선택된 경우, 리사이징을 하지 않고 원본 이미지를 그대로 반환
|
2451
|
+
if w == 'original'
|
2452
|
+
return img # 원본 이미지 그대로 반환
|
2453
|
+
else
|
2454
|
+
begin
|
2455
|
+
if @data['image_type'][0].checked? or @data['image_type'][2].checked?
|
2456
|
+
# 비율을 맞추어 리사이징
|
2457
|
+
img.resize!(w, w * (height.to_f / width.to_f))
|
2458
|
+
else
|
2459
|
+
# 정사각형으로 리사이징
|
2460
|
+
img.resize!(w, w)
|
2461
|
+
end
|
2462
|
+
rescue
|
2463
|
+
img.resize!(w, w) # 예외 처리 시에도 리사이징
|
2362
2464
|
end
|
2363
|
-
rescue
|
2364
|
-
img.resize!(w, w)
|
2365
2465
|
end
|
2466
|
+
|
2467
|
+
# 리사이징된 이미지 저장
|
2366
2468
|
img.write('./image/memory.png')
|
2367
2469
|
end
|
2368
2470
|
|
2471
|
+
def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
|
2472
|
+
size = initial_size
|
2473
|
+
draw.font = font_path
|
2474
|
+
|
2475
|
+
loop do
|
2476
|
+
draw.pointsize = size
|
2477
|
+
words = text.chars # 글자 단위로 자름 (한국어 기준)
|
2478
|
+
lines = []
|
2479
|
+
line = ""
|
2480
|
+
|
2481
|
+
words.each do |char|
|
2482
|
+
test_line = line + char
|
2483
|
+
metrics = draw.get_type_metrics(test_line)
|
2484
|
+
if metrics.width > max_width
|
2485
|
+
lines << line
|
2486
|
+
line = char
|
2487
|
+
else
|
2488
|
+
line = test_line
|
2489
|
+
end
|
2490
|
+
end
|
2491
|
+
lines << line unless line.empty?
|
2492
|
+
|
2493
|
+
line_height = draw.get_type_metrics("가").height
|
2494
|
+
total_height = line_height * lines.size
|
2495
|
+
|
2496
|
+
# 세로 초과 안 하면 성공
|
2497
|
+
if total_height <= max_height || size <= 10
|
2498
|
+
return [lines.join("\n"), size]
|
2499
|
+
else
|
2500
|
+
size -= 2
|
2501
|
+
end
|
2502
|
+
end
|
2503
|
+
end
|
2504
|
+
|
2505
|
+
|
2369
2506
|
def image_text(text1, text2)
|
2370
2507
|
begin
|
2371
2508
|
color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
|
2372
|
-
|
2373
|
-
|
2374
|
-
text = Magick::Draw.new
|
2509
|
+
font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
|
2510
|
+
font2 = './fonts/' + font_files.sample
|
2375
2511
|
color2 = color.sample
|
2376
|
-
|
2377
|
-
|
2512
|
+
|
2513
|
+
img = Magick::Image.read('./image/memory.png').first
|
2514
|
+
draw = Magick::Draw.new
|
2515
|
+
|
2516
|
+
raw_message = "#{text1}\n#{text2}".strip
|
2517
|
+
max_width = img.columns * 0.85
|
2518
|
+
max_height = img.rows * 0.6
|
2519
|
+
|
2378
2520
|
begin
|
2379
2521
|
size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
|
2380
2522
|
rescue
|
2381
2523
|
size = 30
|
2382
2524
|
end
|
2525
|
+
|
2526
|
+
wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
|
2527
|
+
|
2383
2528
|
if @data['이미지설정']['글자그림자'].checked?
|
2384
|
-
img.annotate(
|
2385
|
-
|
2386
|
-
|
2387
|
-
|
2388
|
-
|
2529
|
+
img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
|
2530
|
+
draw.gravity = Magick::CenterGravity
|
2531
|
+
draw.pointsize = adjusted_size
|
2532
|
+
draw.fill = '#000000'
|
2533
|
+
draw.font = font2
|
2389
2534
|
end
|
2390
2535
|
end
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
2536
|
+
|
2537
|
+
draw2 = Magick::Draw.new
|
2538
|
+
img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
|
2539
|
+
draw2.gravity = Magick::CenterGravity
|
2540
|
+
draw2.pointsize = adjusted_size
|
2541
|
+
draw2.fill = color2
|
2542
|
+
draw2.font = font2
|
2395
2543
|
if @data['이미지설정']['글자테두리'].checked?
|
2396
|
-
|
2397
|
-
|
2544
|
+
draw2.stroke_width = 2
|
2545
|
+
draw2.stroke = '#000000'
|
2398
2546
|
end
|
2399
|
-
text.fill = color2
|
2400
|
-
text.font = font2
|
2401
2547
|
end
|
2402
|
-
|
2548
|
+
|
2403
2549
|
img.write('./image/memory.png')
|
2404
2550
|
rescue
|
2405
2551
|
puts '이미지 폰트 불러오기 오류 재시도...'
|
@@ -2433,23 +2579,30 @@ class Wordpress
|
|
2433
2579
|
else
|
2434
2580
|
auto_image()
|
2435
2581
|
end
|
2436
|
-
|
2437
|
-
|
2582
|
+
|
2583
|
+
# '원본'을 포함한 이미지 크기 옵션 추가
|
2584
|
+
image_size = [480, 740, 650, 550, 480, 'original']
|
2438
2585
|
size = 0
|
2439
|
-
|
2586
|
+
|
2587
|
+
for n in 0..5 # 0부터 5까지 반복, '원본' 옵션까지 포함
|
2440
2588
|
if @data['image_size'][n].checked?
|
2441
|
-
if n ==
|
2442
|
-
size =
|
2589
|
+
if n == 5 # '원본'이 선택되었을 경우
|
2590
|
+
size = 'original'
|
2591
|
+
elsif n == 0
|
2592
|
+
size = image_size.sample # 랜덤 선택
|
2443
2593
|
else
|
2444
2594
|
size = image_size[n]
|
2445
2595
|
end
|
2446
2596
|
end
|
2447
2597
|
end
|
2598
|
+
|
2599
|
+
# '원본'이 선택되지 않았다면 기본 값 설정
|
2448
2600
|
if size == 0
|
2449
2601
|
size = 480
|
2450
2602
|
end
|
2603
|
+
|
2604
|
+
change_image_size(size) # 크기 변경 함수 호출
|
2451
2605
|
|
2452
|
-
change_image_size(size)
|
2453
2606
|
|
2454
2607
|
if @data['이미지설정']['필터사용'].checked?
|
2455
2608
|
image_filter()
|
@@ -2457,33 +2610,33 @@ class Wordpress
|
|
2457
2610
|
|
2458
2611
|
if @data['이미지설정']['글자삽입1'].checked?
|
2459
2612
|
if @data['이미지설정']['이미지글자1'].length == 0
|
2460
|
-
|
2613
|
+
image_text_path1 = ''
|
2461
2614
|
else
|
2462
|
-
|
2463
|
-
|
2464
|
-
|
2465
|
-
|
2466
|
-
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2615
|
+
if @data['이미지설정']['글자랜덤'].checked?
|
2616
|
+
image_text_path1 = @data['이미지설정']['이미지글자1'].sample
|
2617
|
+
else
|
2618
|
+
image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
|
2619
|
+
@image_text_soon1 += 1
|
2620
|
+
if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
|
2621
|
+
@image_text_soon1 = 0
|
2622
|
+
end
|
2623
|
+
end
|
2471
2624
|
end
|
2472
2625
|
end
|
2473
2626
|
|
2474
2627
|
if @data['이미지설정']['글자삽입2'].checked?
|
2475
2628
|
if @data['이미지설정']['이미지글자2'].length == 0
|
2476
|
-
|
2629
|
+
image_text_path2 = ''
|
2477
2630
|
else
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2486
|
-
|
2631
|
+
if @data['이미지설정']['글자랜덤'].checked?
|
2632
|
+
image_text_path2 = @data['이미지설정']['이미지글자2'].sample
|
2633
|
+
else
|
2634
|
+
image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
|
2635
|
+
@image_text_soon2 += 1
|
2636
|
+
if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
|
2637
|
+
@image_text_soon2 = 0
|
2638
|
+
end
|
2639
|
+
end
|
2487
2640
|
end
|
2488
2641
|
end
|
2489
2642
|
|
@@ -4894,6 +5047,7 @@ class Wordpress
|
|
4894
5047
|
@data['image_size'][2].checked = false
|
4895
5048
|
@data['image_size'][3].checked = false
|
4896
5049
|
@data['image_size'][4].checked = false
|
5050
|
+
@data['image_size'][5].checked = false
|
4897
5051
|
end
|
4898
5052
|
}
|
4899
5053
|
}
|
@@ -4904,6 +5058,7 @@ class Wordpress
|
|
4904
5058
|
@data['image_size'][2].checked = false
|
4905
5059
|
@data['image_size'][3].checked = false
|
4906
5060
|
@data['image_size'][4].checked = false
|
5061
|
+
@data['image_size'][5].checked = false
|
4907
5062
|
end
|
4908
5063
|
}
|
4909
5064
|
}
|
@@ -4914,6 +5069,7 @@ class Wordpress
|
|
4914
5069
|
@data['image_size'][0].checked = false
|
4915
5070
|
@data['image_size'][3].checked = false
|
4916
5071
|
@data['image_size'][4].checked = false
|
5072
|
+
@data['image_size'][5].checked = false
|
4917
5073
|
end
|
4918
5074
|
}
|
4919
5075
|
}
|
@@ -4924,6 +5080,7 @@ class Wordpress
|
|
4924
5080
|
@data['image_size'][2].checked = false
|
4925
5081
|
@data['image_size'][0].checked = false
|
4926
5082
|
@data['image_size'][4].checked = false
|
5083
|
+
@data['image_size'][5].checked = false
|
4927
5084
|
end
|
4928
5085
|
}
|
4929
5086
|
}
|
@@ -4934,6 +5091,18 @@ class Wordpress
|
|
4934
5091
|
@data['image_size'][2].checked = false
|
4935
5092
|
@data['image_size'][3].checked = false
|
4936
5093
|
@data['image_size'][0].checked = false
|
5094
|
+
@data['image_size'][5].checked = false
|
5095
|
+
end
|
5096
|
+
}
|
5097
|
+
}
|
5098
|
+
@data['image_size'][5] = checkbox('원본 px'){
|
5099
|
+
on_toggled{
|
5100
|
+
if @data['image_size'][5].checked?
|
5101
|
+
@data['image_size'][1].checked = false
|
5102
|
+
@data['image_size'][2].checked = false
|
5103
|
+
@data['image_size'][3].checked = false
|
5104
|
+
@data['image_size'][0].checked = false
|
5105
|
+
@data['image_size'][4].checked = false
|
4937
5106
|
end
|
4938
5107
|
}
|
4939
5108
|
}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cafe_buy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
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-
|
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
|