wp_posting_zon 0.0.3 → 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 +73 -11
- 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 }
|
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: 2025-
|
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: []
|