wp_posting_zon 0.0.2 → 0.0.7
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/wp_posting_zon.rb +90 -18
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6933d304ba0de74739de163a79202d5b0bc88532977b4127a6d13115e4bf1ea0
|
4
|
+
data.tar.gz: 489e272f36bca3b99f9cc8eb5f4f054c45e57e67b5dfaa55a4bd8449a7f98f4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38d59eff423b0bb6cef3795c84a17cbe2b81b5e2d5f39250fe60caf1a62e613c0a902f91c08a8678b7aaa398802e8a2afdc3cc2898e4a85d580e57d20695a7f5
|
7
|
+
data.tar.gz: d25d6707b7761218972979e778f11d37bcc1113383c9915918c1e33d116674508e32ce670b1646121226dd2214a0fa0aa148f9dbb2f30067591480c00aeafeb3
|
data/lib/wp_posting_zon.rb
CHANGED
@@ -11,6 +11,7 @@ require 'open3'
|
|
11
11
|
require 'zlib'
|
12
12
|
require 'stringio'
|
13
13
|
require 'timeout'
|
14
|
+
require 'httpclient'
|
14
15
|
|
15
16
|
class Wordpress
|
16
17
|
include Glimmer
|
@@ -337,24 +338,85 @@ class Wordpress
|
|
337
338
|
return @data2
|
338
339
|
end
|
339
340
|
|
340
|
-
def auto_image
|
341
|
+
def auto_image(keyword = nil)
|
342
|
+
keyword ||= @keyword
|
343
|
+
puts "키워드: #{keyword}"
|
344
|
+
|
345
|
+
client = HTTPClient.new
|
346
|
+
client.default_header = {
|
347
|
+
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
|
348
|
+
'(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
|
349
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
350
|
+
'Accept-Language' => 'en-US,en;q=0.9',
|
351
|
+
'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
|
352
|
+
'X-Requested-With' => 'XMLHttpRequest'
|
353
|
+
}
|
354
|
+
|
355
|
+
retry_count = 0
|
356
|
+
max_retries = 10
|
357
|
+
results = []
|
358
|
+
|
341
359
|
begin
|
342
360
|
page = rand(1..15)
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
361
|
+
url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
|
362
|
+
puts "Request URL: #{url}"
|
363
|
+
res = client.get(url)
|
364
|
+
|
365
|
+
unless res.status == 200
|
366
|
+
puts "HTTP Error: #{res.status}"
|
367
|
+
raise "HTTP Error"
|
348
368
|
end
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
369
|
+
|
370
|
+
json = JSON.parse(res.body)
|
371
|
+
results = json['results']
|
372
|
+
mm = []
|
373
|
+
|
374
|
+
results.each do |photo|
|
375
|
+
full_url = photo.dig('urls', 'full').to_s
|
376
|
+
regular_url = photo.dig('urls', 'regular').to_s
|
377
|
+
|
378
|
+
if full_url.start_with?("https://images.unsplash.com/photo-") &&
|
379
|
+
regular_url.include?("1080")
|
380
|
+
mm << full_url
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
if mm.empty?
|
385
|
+
raise "No matching image"
|
386
|
+
end
|
387
|
+
|
388
|
+
selected_url = mm.sample
|
389
|
+
Down.download(selected_url, destination: "./image/memory.png")
|
390
|
+
puts "이미지 다운로드 완료: #{selected_url}"
|
391
|
+
|
392
|
+
rescue => e
|
393
|
+
retry_count += 1
|
394
|
+
puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
|
395
|
+
sleep(3)
|
396
|
+
if retry_count < max_retries
|
354
397
|
retry
|
398
|
+
else
|
399
|
+
puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
|
400
|
+
|
401
|
+
if results && !results.empty?
|
402
|
+
random_photo = results.sample
|
403
|
+
fallback_url = random_photo.dig('urls', 'full')
|
404
|
+
if fallback_url
|
405
|
+
Down.download(fallback_url, destination: "./image/memory.png")
|
406
|
+
puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
|
407
|
+
else
|
408
|
+
puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
|
409
|
+
color_image
|
410
|
+
end
|
411
|
+
else
|
412
|
+
puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
|
413
|
+
color_image
|
414
|
+
end
|
415
|
+
end
|
355
416
|
end
|
356
417
|
end
|
357
418
|
|
419
|
+
|
358
420
|
def color_image
|
359
421
|
color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
|
360
422
|
image = Magick::Image.new(740, 740) { |k| k.background_color = color.sample }
|
@@ -2196,17 +2258,27 @@ class Wordpress
|
|
2196
2258
|
}
|
2197
2259
|
button('폴더째로불러오기'){
|
2198
2260
|
stretchy false
|
2199
|
-
on_clicked{
|
2261
|
+
on_clicked {
|
2200
2262
|
path = @data['이미지설정']['폴더경로'].text.to_s.force_encoding('utf-8')
|
2201
|
-
Dir.entries(@data['이미지설정']['폴더경로'].text.to_s).each do |file|
|
2202
|
-
if file == '.' or file == '..'
|
2203
2263
|
|
2204
|
-
|
2205
|
-
|
2264
|
+
# 경로가 유효한지 확인
|
2265
|
+
if Dir.exist?(path)
|
2266
|
+
Dir.entries(path).each do |file|
|
2267
|
+
if file == '.' or file == '..'
|
2268
|
+
next
|
2269
|
+
else
|
2270
|
+
# 폴더 내의 파일을 이미지 리스트에 추가
|
2271
|
+
@data['이미지설정']['이미지'] << [false, file, path + "\\" + file.force_encoding('utf-8')]
|
2272
|
+
end
|
2206
2273
|
end
|
2274
|
+
|
2275
|
+
# 마지막 빈 항목 추가 후 제거 (원래 로직에 맞춰)
|
2276
|
+
@data['이미지설정']['이미지'] << []
|
2277
|
+
@data['이미지설정']['이미지'].pop
|
2278
|
+
else
|
2279
|
+
# 경로가 존재하지 않으면 경고 메시지 출력
|
2280
|
+
puts "경로가 존재하지 않습니다: #{path}"
|
2207
2281
|
end
|
2208
|
-
@data['이미지설정']['이미지'] << []
|
2209
|
-
@data['이미지설정']['이미지'].pop
|
2210
2282
|
}
|
2211
2283
|
}
|
2212
2284
|
}
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wp_posting_zon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zon
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-05-23 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: File to Clipboard gem
|
14
13
|
email: mymin26@naver.com
|
@@ -21,7 +20,6 @@ homepage: ''
|
|
21
20
|
licenses:
|
22
21
|
- zon
|
23
22
|
metadata: {}
|
24
|
-
post_install_message:
|
25
23
|
rdoc_options: []
|
26
24
|
require_paths:
|
27
25
|
- lib
|
@@ -36,8 +34,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
34
|
- !ruby/object:Gem::Version
|
37
35
|
version: '0'
|
38
36
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
40
|
-
signing_key:
|
37
|
+
rubygems_version: 3.6.7
|
41
38
|
specification_version: 4
|
42
39
|
summary: file to clipboard
|
43
40
|
test_files: []
|