cafe_basics_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_basics_duo.rb +232 -63
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed29b474605d5e69da6839887f2098f9440775ec05d0702341b143138a0c654b
4
- data.tar.gz: bdb4ed6fee966c5f02f4089f2ad2f60858bcd3e2cc4d778848130cc642fd355c
3
+ metadata.gz: c473b00e756bcba3cb0b76ab0ee1ddc196f3319dc7ba299afc2806fd06ab3d48
4
+ data.tar.gz: 4b2aeea289d103f695795bd56d96aadb0395849ff705ae2b3591603e20dba450
5
5
  SHA512:
6
- metadata.gz: a191bbefbfbfc7a7f1a46a6de3578da551839430a635d0add360e8e6572c076f1ace730a3fa45ddbe70e62f31b1adf1dc52ec369b0f56682afc260639231b4bf
7
- data.tar.gz: 65dc2ff26d0ffc33ace43524d2c729a554aae460a5e11241865cdb089142cad4a277905226905993b143b84f55aefbd7e53935948ffb4b6f295f733eed3848c9
6
+ metadata.gz: 917d23972fe6ac3fa9d6dfa56802440dc16dae3bd02b981611b4ad2b5d1a30d772b9aaf017219ad90d86b902f028d268ce9fafa9f2d62c6b6691cf7cf2b444b9
7
+ data.tar.gz: c5f74ba2b30f6b11ed80c990f3a2c62de1797db3c6923de033c52b23e4209bdaf02c45963023066adcd68525f4d3c0f3a22ed270eeb7c87f2743e6180f9be384
@@ -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"
@@ -2031,21 +2063,81 @@ class Wordpress
2031
2063
 
2032
2064
 
2033
2065
 
2034
- def auto_image
2066
+ def auto_image(keyword = nil)
2067
+ keyword ||= @keyword
2068
+ puts "키워드: #{keyword}"
2069
+
2070
+ client = HTTPClient.new
2071
+ client.default_header = {
2072
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
2073
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
2074
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
2075
+ 'Accept-Language' => 'en-US,en;q=0.9',
2076
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
2077
+ 'X-Requested-With' => 'XMLHttpRequest'
2078
+ }
2079
+
2080
+ retry_count = 0
2081
+ max_retries = 10
2082
+ results = []
2083
+
2035
2084
  begin
2036
2085
  page = rand(1..15)
2037
- http = HTTP.get('https://unsplash.com/napi/photos?per_page=12&page='+page.to_s)
2038
- json = JSON.parse(http.to_s)
2039
- mm = Array.new
2040
- json.each do |i|
2041
- mm << i['urls']['full']
2086
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
2087
+ puts "Request URL: #{url}"
2088
+ res = client.get(url)
2089
+
2090
+ unless res.status == 200
2091
+ puts "HTTP Error: #{res.status}"
2092
+ raise "HTTP Error"
2042
2093
  end
2043
- url = mm.sample
2044
- Down.download(url, destination: "./image/memory.png")
2045
- rescue
2046
- puts 'auto_image 일시적 error 5초후 제시도...'
2047
- sleep(5)
2094
+
2095
+ json = JSON.parse(res.body)
2096
+ results = json['results']
2097
+ mm = []
2098
+
2099
+ results.each do |photo|
2100
+ full_url = photo.dig('urls', 'full').to_s
2101
+ regular_url = photo.dig('urls', 'regular').to_s
2102
+
2103
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
2104
+ regular_url.include?("1080")
2105
+ mm << full_url
2106
+ end
2107
+ end
2108
+
2109
+ if mm.empty?
2110
+ raise "No matching image"
2111
+ end
2112
+
2113
+ selected_url = mm.sample
2114
+ Down.download(selected_url, destination: "./image/memory.png")
2115
+ puts "이미지 다운로드 완료: #{selected_url}"
2116
+
2117
+ rescue => e
2118
+ retry_count += 1
2119
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
2120
+ sleep(3)
2121
+ if retry_count < max_retries
2048
2122
  retry
2123
+ else
2124
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
2125
+
2126
+ if results && !results.empty?
2127
+ random_photo = results.sample
2128
+ fallback_url = random_photo.dig('urls', 'full')
2129
+ if fallback_url
2130
+ Down.download(fallback_url, destination: "./image/memory.png")
2131
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
2132
+ else
2133
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
2134
+ color_image
2135
+ end
2136
+ else
2137
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
2138
+ color_image
2139
+ end
2140
+ end
2049
2141
  end
2050
2142
  end
2051
2143
 
@@ -2084,52 +2176,106 @@ class Wordpress
2084
2176
  img = Magick::Image.read('./image/memory.png').first
2085
2177
  width = img.columns
2086
2178
  height = img.rows
2087
- begin
2088
- if @data['image_type'][0].checked? or @data['image_type'][2].checked?
2089
- img.resize!(w, w*(height.to_f/width.to_f))
2090
- else
2091
- img.resize!(w, w)
2179
+
2180
+ # '원본' 선택된 경우, 리사이징을 하지 않고 원본 이미지를 그대로 반환
2181
+ if w == 'original'
2182
+ return img # 원본 이미지 그대로 반환
2183
+ else
2184
+ begin
2185
+ if @data['image_type'][0].checked? or @data['image_type'][2].checked?
2186
+ # 비율을 맞추어 리사이징
2187
+ img.resize!(w, w * (height.to_f / width.to_f))
2188
+ else
2189
+ # 정사각형으로 리사이징
2190
+ img.resize!(w, w)
2191
+ end
2192
+ rescue
2193
+ img.resize!(w, w) # 예외 처리 시에도 리사이징
2092
2194
  end
2093
- rescue
2094
- img.resize!(w, w)
2095
2195
  end
2196
+
2197
+ # 리사이징된 이미지 저장
2096
2198
  img.write('./image/memory.png')
2097
2199
  end
2098
2200
 
2201
+ def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
2202
+ size = initial_size
2203
+ draw.font = font_path
2204
+
2205
+ loop do
2206
+ draw.pointsize = size
2207
+ words = text.chars # 글자 단위로 자름 (한국어 기준)
2208
+ lines = []
2209
+ line = ""
2210
+
2211
+ words.each do |char|
2212
+ test_line = line + char
2213
+ metrics = draw.get_type_metrics(test_line)
2214
+ if metrics.width > max_width
2215
+ lines << line
2216
+ line = char
2217
+ else
2218
+ line = test_line
2219
+ end
2220
+ end
2221
+ lines << line unless line.empty?
2222
+
2223
+ line_height = draw.get_type_metrics("가").height
2224
+ total_height = line_height * lines.size
2225
+
2226
+ # 세로 초과 안 하면 성공
2227
+ if total_height <= max_height || size <= 10
2228
+ return [lines.join("\n"), size]
2229
+ else
2230
+ size -= 2
2231
+ end
2232
+ end
2233
+ end
2234
+
2235
+
2099
2236
  def image_text(text1, text2)
2100
2237
  begin
2101
2238
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
2102
- font = Dir.entries('./fonts')
2103
- img = Magick::Image.read('./image/memory.png').first
2104
- text = Magick::Draw.new
2239
+ font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
2240
+ font2 = './fonts/' + font_files.sample
2105
2241
  color2 = color.sample
2106
- font2 = './fonts/'+font.sample
2107
- message = text1.to_s+"\n"+text2.to_s
2242
+
2243
+ img = Magick::Image.read('./image/memory.png').first
2244
+ draw = Magick::Draw.new
2245
+
2246
+ raw_message = "#{text1}\n#{text2}".strip
2247
+ max_width = img.columns * 0.85
2248
+ max_height = img.rows * 0.6
2249
+
2108
2250
  begin
2109
2251
  size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
2110
2252
  rescue
2111
2253
  size = 30
2112
2254
  end
2255
+
2256
+ wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
2257
+
2113
2258
  if @data['이미지설정']['글자그림자'].checked?
2114
- img.annotate(text, 0,0, +3,+3, message) do
2115
- text.gravity = Magick::CenterGravity
2116
- text.pointsize = size
2117
- text.fill = '#000000'
2118
- text.font = font2
2259
+ img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
2260
+ draw.gravity = Magick::CenterGravity
2261
+ draw.pointsize = adjusted_size
2262
+ draw.fill = '#000000'
2263
+ draw.font = font2
2119
2264
  end
2120
2265
  end
2121
-
2122
- img.annotate(text, 0,0,0,0, message) do
2123
- text.gravity = Magick::CenterGravity
2124
- text.pointsize = size
2266
+
2267
+ draw2 = Magick::Draw.new
2268
+ img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
2269
+ draw2.gravity = Magick::CenterGravity
2270
+ draw2.pointsize = adjusted_size
2271
+ draw2.fill = color2
2272
+ draw2.font = font2
2125
2273
  if @data['이미지설정']['글자테두리'].checked?
2126
- text.stroke_width = 2
2127
- text.stroke = '#000000'
2274
+ draw2.stroke_width = 2
2275
+ draw2.stroke = '#000000'
2128
2276
  end
2129
- text.fill = color2
2130
- text.font = font2
2131
2277
  end
2132
-
2278
+
2133
2279
  img.write('./image/memory.png')
2134
2280
  rescue
2135
2281
  puts '이미지 폰트 불러오기 오류 재시도...'
@@ -2163,23 +2309,30 @@ class Wordpress
2163
2309
  else
2164
2310
  auto_image()
2165
2311
  end
2166
-
2167
- image_size = [480,740,650,550,480]
2312
+
2313
+ # '원본'을 포함한 이미지 크기 옵션 추가
2314
+ image_size = [480, 740, 650, 550, 480, 'original']
2168
2315
  size = 0
2169
- for n in 0..4
2316
+
2317
+ for n in 0..5 # 0부터 5까지 반복, '원본' 옵션까지 포함
2170
2318
  if @data['image_size'][n].checked?
2171
- if n == 0
2172
- size = image_size.sample
2319
+ if n == 5 # '원본'이 선택되었을 경우
2320
+ size = 'original'
2321
+ elsif n == 0
2322
+ size = image_size.sample # 랜덤 선택
2173
2323
  else
2174
2324
  size = image_size[n]
2175
2325
  end
2176
2326
  end
2177
2327
  end
2328
+
2329
+ # '원본'이 선택되지 않았다면 기본 값 설정
2178
2330
  if size == 0
2179
2331
  size = 480
2180
2332
  end
2333
+
2334
+ change_image_size(size) # 크기 변경 함수 호출
2181
2335
 
2182
- change_image_size(size)
2183
2336
 
2184
2337
  if @data['이미지설정']['필터사용'].checked?
2185
2338
  image_filter()
@@ -2187,33 +2340,33 @@ class Wordpress
2187
2340
 
2188
2341
  if @data['이미지설정']['글자삽입1'].checked?
2189
2342
  if @data['이미지설정']['이미지글자1'].length == 0
2190
- image_text_path1 = ''
2191
- else
2192
- if @data['이미지설정']['글자랜덤'].checked?
2193
- image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2343
+ image_text_path1 = ''
2194
2344
  else
2195
- image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2196
- @image_text_soon1 += 1
2197
- if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2198
- @image_text_soon1 = 0
2199
- end
2200
- end
2345
+ if @data['이미지설정']['글자랜덤'].checked?
2346
+ image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2347
+ else
2348
+ image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2349
+ @image_text_soon1 += 1
2350
+ if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2351
+ @image_text_soon1 = 0
2352
+ end
2353
+ end
2201
2354
  end
2202
2355
  end
2203
2356
 
2204
2357
  if @data['이미지설정']['글자삽입2'].checked?
2205
2358
  if @data['이미지설정']['이미지글자2'].length == 0
2206
- image_text_path2 = ''
2207
- else
2208
- if @data['이미지설정']['글자랜덤'].checked?
2209
- image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2359
+ image_text_path2 = ''
2210
2360
  else
2211
- image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2212
- @image_text_soon2 += 1
2213
- if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2214
- @image_text_soon2 = 0
2215
- end
2216
- end
2361
+ if @data['이미지설정']['글자랜덤'].checked?
2362
+ image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2363
+ else
2364
+ image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2365
+ @image_text_soon2 += 1
2366
+ if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2367
+ @image_text_soon2 = 0
2368
+ end
2369
+ end
2217
2370
  end
2218
2371
  end
2219
2372
 
@@ -4583,6 +4736,7 @@ class Wordpress
4583
4736
  @data['image_size'][2].checked = false
4584
4737
  @data['image_size'][3].checked = false
4585
4738
  @data['image_size'][4].checked = false
4739
+ @data['image_size'][5].checked = false
4586
4740
  end
4587
4741
  }
4588
4742
  }
@@ -4593,6 +4747,7 @@ class Wordpress
4593
4747
  @data['image_size'][2].checked = false
4594
4748
  @data['image_size'][3].checked = false
4595
4749
  @data['image_size'][4].checked = false
4750
+ @data['image_size'][5].checked = false
4596
4751
  end
4597
4752
  }
4598
4753
  }
@@ -4603,6 +4758,7 @@ class Wordpress
4603
4758
  @data['image_size'][0].checked = false
4604
4759
  @data['image_size'][3].checked = false
4605
4760
  @data['image_size'][4].checked = false
4761
+ @data['image_size'][5].checked = false
4606
4762
  end
4607
4763
  }
4608
4764
  }
@@ -4613,6 +4769,7 @@ class Wordpress
4613
4769
  @data['image_size'][2].checked = false
4614
4770
  @data['image_size'][0].checked = false
4615
4771
  @data['image_size'][4].checked = false
4772
+ @data['image_size'][5].checked = false
4616
4773
  end
4617
4774
  }
4618
4775
  }
@@ -4623,6 +4780,18 @@ class Wordpress
4623
4780
  @data['image_size'][2].checked = false
4624
4781
  @data['image_size'][3].checked = false
4625
4782
  @data['image_size'][0].checked = false
4783
+ @data['image_size'][5].checked = false
4784
+ end
4785
+ }
4786
+ }
4787
+ @data['image_size'][5] = checkbox('원본 px'){
4788
+ on_toggled{
4789
+ if @data['image_size'][5].checked?
4790
+ @data['image_size'][1].checked = false
4791
+ @data['image_size'][2].checked = false
4792
+ @data['image_size'][3].checked = false
4793
+ @data['image_size'][0].checked = false
4794
+ @data['image_size'][4].checked = false
4626
4795
  end
4627
4796
  }
4628
4797
  }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cafe_basics_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