wp_posting_duo 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/wp_posting_duo.rb +73 -11
  3. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1cb4f149042a682b91d238851c8c25987205163a407d85b9a8e926799c69cec
4
- data.tar.gz: aae789d19521465e6a960341a72effe0c486ddd493b10e7a5f3aebf3761feaf9
3
+ metadata.gz: 47717ece00cb608e31ccc7f3a77dfa14d31f3e9bbdc324c4265b4d3fe2792b07
4
+ data.tar.gz: ac8078e3de95f30eae0ec01ee3a3916623be1b2cb0f97f2c353ebc87f38603a4
5
5
  SHA512:
6
- metadata.gz: 5fe7df87ea12055fbd76acda4cb834ac1151b479cb72f1c044156a582a20f9bdd839944b12b93f463bd5a45396bc7e32cb0867e7213fa706e921fd6bdaf7005a
7
- data.tar.gz: fb959af20e28c265f1fa2e408c98b369d0bcf37db83e50c24195d6bb63afb4cf5763dd5d56dda162a647974defede663a2b6719fe5092f3c0fc65b0256d9c5ab
6
+ metadata.gz: 17b374d7691fe13d88491bd385ea8a3aec057dc968b47b22e8c92cf6e7978762ca2aa50bb8ef8460b5748428ec40613ec6165863647048c5bb4f57384fb28816
7
+ data.tar.gz: ca106a19a91650171725c16058fc6fe076dcccacd66536a6cc7eb9100d31f1b5f00afc9fbe48ea21b002e2d1d6d110bc576642e95404bc4836e6d4ffc3e81d21
@@ -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
@@ -402,24 +403,85 @@ class Wordpress
402
403
  return @data2
403
404
  end
404
405
 
405
- def auto_image
406
+ def auto_image(keyword = nil)
407
+ keyword ||= @keyword
408
+ puts "키워드: #{keyword}"
409
+
410
+ client = HTTPClient.new
411
+ client.default_header = {
412
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
413
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
414
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
415
+ 'Accept-Language' => 'en-US,en;q=0.9',
416
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
417
+ 'X-Requested-With' => 'XMLHttpRequest'
418
+ }
419
+
420
+ retry_count = 0
421
+ max_retries = 10
422
+ results = []
423
+
406
424
  begin
407
425
  page = rand(1..15)
408
- http = HTTP.get('https://unsplash.com/napi/photos?per_page=12&page='+page.to_s)
409
- json = JSON.parse(http.to_s)
410
- mm = Array.new
411
- json.each do |i|
412
- mm << i['urls']['full']
426
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
427
+ puts "Request URL: #{url}"
428
+ res = client.get(url)
429
+
430
+ unless res.status == 200
431
+ puts "HTTP Error: #{res.status}"
432
+ raise "HTTP Error"
413
433
  end
414
- url = mm.sample
415
- Down.download(url, destination: "./image/memory.png")
416
- rescue
417
- puts 'image auto download error 5초후 재시도...'
418
- sleep(5)
434
+
435
+ json = JSON.parse(res.body)
436
+ results = json['results']
437
+ mm = []
438
+
439
+ results.each do |photo|
440
+ full_url = photo.dig('urls', 'full').to_s
441
+ regular_url = photo.dig('urls', 'regular').to_s
442
+
443
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
444
+ regular_url.include?("1080")
445
+ mm << full_url
446
+ end
447
+ end
448
+
449
+ if mm.empty?
450
+ raise "No matching image"
451
+ end
452
+
453
+ selected_url = mm.sample
454
+ Down.download(selected_url, destination: "./image/memory.png")
455
+ puts "이미지 다운로드 완료: #{selected_url}"
456
+
457
+ rescue => e
458
+ retry_count += 1
459
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
460
+ sleep(3)
461
+ if retry_count < max_retries
419
462
  retry
463
+ else
464
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
465
+
466
+ if results && !results.empty?
467
+ random_photo = results.sample
468
+ fallback_url = random_photo.dig('urls', 'full')
469
+ if fallback_url
470
+ Down.download(fallback_url, destination: "./image/memory.png")
471
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
472
+ else
473
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
474
+ color_image
475
+ end
476
+ else
477
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
478
+ color_image
479
+ end
480
+ end
420
481
  end
421
482
  end
422
483
 
484
+
423
485
  def color_image
424
486
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
425
487
  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_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
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: 2024-01-09 00:00:00.000000000 Z
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.3.7
40
- signing_key:
37
+ rubygems_version: 3.6.7
41
38
  specification_version: 4
42
39
  summary: file to clipboard
43
40
  test_files: []