nblog_zon 111.115.779 → 111.117.779

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/nblog_zon.rb +125 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6f2c441d7cfe974b89ba6f8e7901d9cf833a31fbbcf68bce6b267781818944d
4
- data.tar.gz: 72480bf7945e6e183b4587ca094c353fb0009526f1160c67f9b8f11bb892c175
3
+ metadata.gz: 236e11f30c46482c090215649db157d3719f868b63f9da2122f85365e6d8ce31
4
+ data.tar.gz: 0abdfd4cae1a308ae9b099601a2acffe18d882e85a0e3ec42f68c52a3d4a3935
5
5
  SHA512:
6
- metadata.gz: 17d12511ac2cf7d50b1f6d02cf3f654f0e856ebbe5974b0be1e477c7f35aca14c29e9c4348bb78ca545d72b4985018ce868340c97cb3fbf3fa57caf728bfb17a
7
- data.tar.gz: c04d5f5b542d761ed299cef4dff7b73c803107a295d550d2344fc6a4fcd59dc065b265286e5391a701546f144daaf6d2ebb577c64a3b47eff5332f5e8a4ecbaa
6
+ metadata.gz: 07a350b2743414ecc315caa68635366ec5b599dfc5586dfb8f8af04b76e88442e86cf17dffefe8d1279151d34186d47c71832222f976063a19a1e9ebf0b805a0
7
+ data.tar.gz: 64145e27e56ed19e803445de3537499ba75d84f4a780eaeea613b0743a046595b976cf74d44c22f8b71802d6163136f6c7f35ab0392fbc218d189f59afce95a1
data/lib/nblog_zon.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
@@ -2153,21 +2154,81 @@ class Wordpress
2153
2154
  return @data2
2154
2155
  end
2155
2156
 
2156
- def auto_image
2157
+ def auto_image(keyword = nil)
2158
+ keyword ||= @keyword
2159
+ puts "키워드: #{keyword}"
2160
+
2161
+ client = HTTPClient.new
2162
+ client.default_header = {
2163
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
2164
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
2165
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
2166
+ 'Accept-Language' => 'en-US,en;q=0.9',
2167
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
2168
+ 'X-Requested-With' => 'XMLHttpRequest'
2169
+ }
2170
+
2171
+ retry_count = 0
2172
+ max_retries = 10
2173
+ results = []
2174
+
2157
2175
  begin
2158
2176
  page = rand(1..15)
2159
- http = HTTP.get('https://unsplash.com/napi/photos?per_page=12&page='+page.to_s)
2160
- json = JSON.parse(http.to_s)
2161
- mm = Array.new
2162
- json.each do |i|
2163
- mm << i['urls']['full']
2177
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
2178
+ puts "Request URL: #{url}"
2179
+ res = client.get(url)
2180
+
2181
+ unless res.status == 200
2182
+ puts "HTTP Error: #{res.status}"
2183
+ raise "HTTP Error"
2164
2184
  end
2165
- url = mm.sample
2166
- Down.download(url, destination: "./image/memory.png")
2167
- rescue
2168
- puts 'auto_image 일시적 error 5초후 제시도...'
2169
- sleep(5)
2185
+
2186
+ json = JSON.parse(res.body)
2187
+ results = json['results']
2188
+ mm = []
2189
+
2190
+ results.each do |photo|
2191
+ full_url = photo.dig('urls', 'full').to_s
2192
+ regular_url = photo.dig('urls', 'regular').to_s
2193
+
2194
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
2195
+ regular_url.include?("1080")
2196
+ mm << full_url
2197
+ end
2198
+ end
2199
+
2200
+ if mm.empty?
2201
+ raise "No matching image"
2202
+ end
2203
+
2204
+ selected_url = mm.sample
2205
+ Down.download(selected_url, destination: "./image/memory.png")
2206
+ puts "이미지 다운로드 완료: #{selected_url}"
2207
+
2208
+ rescue => e
2209
+ retry_count += 1
2210
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
2211
+ sleep(3)
2212
+ if retry_count < max_retries
2170
2213
  retry
2214
+ else
2215
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
2216
+
2217
+ if results && !results.empty?
2218
+ random_photo = results.sample
2219
+ fallback_url = random_photo.dig('urls', 'full')
2220
+ if fallback_url
2221
+ Down.download(fallback_url, destination: "./image/memory.png")
2222
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
2223
+ else
2224
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
2225
+ color_image
2226
+ end
2227
+ else
2228
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
2229
+ color_image
2230
+ end
2231
+ end
2171
2232
  end
2172
2233
  end
2173
2234
 
@@ -2324,18 +2385,40 @@ class Wordpress
2324
2385
  image_filter()
2325
2386
  end
2326
2387
 
2327
- insert_image_text1 = ''
2328
- insert_image_text2 = ''
2329
2388
  if @data['이미지설정']['글자삽입1'].checked?
2330
- insert_image_text1 = @data['이미지설정']['이미지글자1'].sample
2389
+ if @data['이미지설정']['이미지글자1'].length == 0
2390
+ image_text_path1 = ''
2391
+ else
2392
+ if @data['이미지설정']['글자랜덤'].checked?
2393
+ image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2394
+ else
2395
+ image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2396
+ @image_text_soon1 += 1
2397
+ if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2398
+ @image_text_soon1 = 0
2399
+ end
2400
+ end
2401
+ end
2331
2402
  end
2332
2403
 
2333
2404
  if @data['이미지설정']['글자삽입2'].checked?
2334
- insert_image_text2 = @data['이미지설정']['이미지글자2'].sample
2405
+ if @data['이미지설정']['이미지글자2'].length == 0
2406
+ image_text_path2 = ''
2407
+ else
2408
+ if @data['이미지설정']['글자랜덤'].checked?
2409
+ image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2410
+ else
2411
+ image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2412
+ @image_text_soon2 += 1
2413
+ if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2414
+ @image_text_soon2 = 0
2415
+ end
2416
+ end
2417
+ end
2335
2418
  end
2336
-
2419
+
2337
2420
  if @data['이미지설정']['글자삽입1'].checked? or @data['이미지설정']['글자삽입2'].checked?
2338
- image_text(insert_image_text1, insert_image_text2)
2421
+ image_text(image_text_path1, image_text_path2)
2339
2422
  end
2340
2423
 
2341
2424
  if @data['이미지설정']['테두리사용'].checked?
@@ -2399,6 +2482,8 @@ class Wordpress
2399
2482
  title_soon = 0
2400
2483
  keyword_soon = 0
2401
2484
  content_soon = 0
2485
+ @image_text_soon1 = 0
2486
+ @image_text_soon2 = 0
2402
2487
  @my_ip = 'init'
2403
2488
  @image_counter = 0
2404
2489
  @inumber2 = 0
@@ -4767,9 +4852,30 @@ class Wordpress
4767
4852
  top 1
4768
4853
  left 6
4769
4854
  }
4770
- @data['이미지설정']['필터사용'] = checkbox('필터사용(색상 사진 적용불가)'){
4855
+ @data['이미지설정']['글자순서'] = checkbox('글자 리스트 순서대로 사용'){
4771
4856
  top 2
4772
4857
  left 0
4858
+ on_toggled{
4859
+ if @data['이미지설정']['글자순서'].checked?
4860
+ @data['이미지설정']['글자랜덤'].checked = false
4861
+ end
4862
+ }
4863
+ }
4864
+
4865
+ @data['이미지설정']['글자랜덤'] = checkbox('글자 리스트 랜덤으로 사용'){
4866
+ top 2
4867
+ left 1
4868
+ on_toggled{
4869
+ if @data['이미지설정']['글자랜덤'].checked?
4870
+ @data['이미지설정']['글자순서'].checked = false
4871
+ end
4872
+ }
4873
+ }
4874
+
4875
+
4876
+ @data['이미지설정']['필터사용'] = checkbox('필터사용(색상 사진 적용불가)'){
4877
+ top 2
4878
+ left 2
4773
4879
  }
4774
4880
  @data['이미지설정']['테두리사용'] = checkbox('테두리 사용'){
4775
4881
  top 3
@@ -5778,6 +5884,7 @@ class Wordpress
5778
5884
  @data['포스트설정']['공감허용'].checked = true
5779
5885
  @data['포스트설정']['발행기능'].checked = true
5780
5886
  @data['포스트설정']['인용구랜덤'].checked = true
5887
+ @data['이미지설정']['글자순서'].checked = true
5781
5888
  }.show
5782
5889
  end
5783
5890
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nblog_zon
3
3
  version: !ruby/object:Gem::Version
4
- version: 111.115.779
4
+ version: 111.117.779
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: rnjstnswp123@naver.com