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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/wp_posting_zon.rb +73 -11
  3. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90696d79e57c50464e4d6ef3278261617a1fbb15990365b5c9da07f8dbeed5cd
4
- data.tar.gz: a6d5cc1cccac9fe3c5bdc8c064f7874d7b3c8e86c9733ce3828c10f81d1ffe87
3
+ metadata.gz: 6933d304ba0de74739de163a79202d5b0bc88532977b4127a6d13115e4bf1ea0
4
+ data.tar.gz: 489e272f36bca3b99f9cc8eb5f4f054c45e57e67b5dfaa55a4bd8449a7f98f4f
5
5
  SHA512:
6
- metadata.gz: ec7085474ca62d8cb9d73ebc5eb4f5827e2a5d1d5eb7537a7f7f03080036a0f74191aa88146379e9f1bae7d1b6a294dc170decd2fcc886a84f90156bcaaff160
7
- data.tar.gz: cc08cb475aad2a23ed8a48e3c17e1ced3f155d953a6877cc05753c3d88415ab73f7621b7c0b5a54174fd41af813c7c68b38fee6c2fb44045f4718ed05b1afa86
6
+ metadata.gz: 38d59eff423b0bb6cef3795c84a17cbe2b81b5e2d5f39250fe60caf1a62e613c0a902f91c08a8678b7aaa398802e8a2afdc3cc2898e4a85d580e57d20695a7f5
7
+ data.tar.gz: d25d6707b7761218972979e778f11d37bcc1113383c9915918c1e33d116674508e32ce670b1646121226dd2214a0fa0aa148f9dbb2f30067591480c00aeafeb3
@@ -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
- http = HTTP.get('https://unsplash.com/napi/photos?per_page=12&page='+page.to_s)
344
- json = JSON.parse(http.to_s)
345
- mm = Array.new
346
- json.each do |i|
347
- mm << i['urls']['full']
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
- url = mm.sample
350
- Down.download(url, destination: "./image/memory.png")
351
- rescue
352
- puts 'image auto download error 5초후 재시도...'
353
- sleep(5)
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.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: 2025-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: []