tiupd 0.0.3 → 0.0.5

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/tiupd.rb +73 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a41726f93df2db3b90b5d4f502744dfc8f36581b00b094dd2225c86b16bd760b
4
- data.tar.gz: 8df09a7a38bac32622624e707d9934eaa87dea1391e73f564aa61b7f9cda5661
3
+ metadata.gz: 56b4f28660c4b6f5d64a447aade1fbc041026f28ddd65a055f9fef207b9d07ff
4
+ data.tar.gz: 3ab09b97e0363e3f79de0ea73f81f2352af84d6b59318a44c5aa0987844b1116
5
5
  SHA512:
6
- metadata.gz: 7cdacbf16ec6d55f8cf1ebf6fcad6e23bb5c28165fb6eefd318b19cdfd681417537e299b32123f4e1ae5fc3145307214bd191e6465c3e58c7ca2dd9a812a2fc1
7
- data.tar.gz: 6ae1ee97f0f4d27bef1bdb5261b115f2db3f7a0bb236128539a78f52eb310ff5f361ef16317ed56aba0a50135c4e5a0681c0f180b6675054b9f411a895c47ae4
6
+ metadata.gz: 225000abf425d025aea146a9aef4d5de63f45fc15dedc08e3e0d349890d6603d9468999d76dd7af3cceacd1f2348c1ea41ce5f4159ab32a91abf267caed4eef9
7
+ data.tar.gz: 15351bdd1f5307b00b138de62f609d4e19ee7511f73e69a83ac1c4b9e107ee91a40daf756be179083e3aae3240d8940f32c93f089e17bd239914fac23a8848e0
data/lib/tiupd.rb CHANGED
@@ -14,7 +14,8 @@ require 'crack'
14
14
  require 'uri'
15
15
  require 'auto_click'
16
16
  require 'rainbow/refinement'
17
- require 'win32ole'
17
+ require 'win32ole'
18
+ require 'httpclient'
18
19
  include AutoClickMethods
19
20
  using Rainbow
20
21
  include Glimmer
@@ -948,21 +949,81 @@ class Wordpress
948
949
 
949
950
 
950
951
 
951
- def auto_image
952
+ def auto_image(keyword = nil)
953
+ keyword ||= @keyword
954
+ puts "키워드: #{keyword}"
955
+
956
+ client = HTTPClient.new
957
+ client.default_header = {
958
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
959
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
960
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
961
+ 'Accept-Language' => 'en-US,en;q=0.9',
962
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
963
+ 'X-Requested-With' => 'XMLHttpRequest'
964
+ }
965
+
966
+ retry_count = 0
967
+ max_retries = 10
968
+ results = []
969
+
952
970
  begin
953
971
  page = rand(1..15)
954
- http = HTTP.get('https://unsplash.com/napi/photos?per_page=12&page='+page.to_s)
955
- json = JSON.parse(http.to_s)
956
- mm = Array.new
957
- json.each do |i|
958
- mm << i['urls']['full']
972
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
973
+ puts "Request URL: #{url}"
974
+ res = client.get(url)
975
+
976
+ unless res.status == 200
977
+ puts "HTTP Error: #{res.status}"
978
+ raise "HTTP Error"
959
979
  end
960
- url = mm.sample
961
- Down.download(url, destination: "./image/memory.png")
962
- rescue
963
- puts 'auto_image 일시적 error 5초후 제시도...'
964
- sleep(5)
980
+
981
+ json = JSON.parse(res.body)
982
+ results = json['results']
983
+ mm = []
984
+
985
+ results.each do |photo|
986
+ full_url = photo.dig('urls', 'full').to_s
987
+ regular_url = photo.dig('urls', 'regular').to_s
988
+
989
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
990
+ regular_url.include?("1080")
991
+ mm << full_url
992
+ end
993
+ end
994
+
995
+ if mm.empty?
996
+ raise "No matching image"
997
+ end
998
+
999
+ selected_url = mm.sample
1000
+ Down.download(selected_url, destination: "./image/memory.png")
1001
+ puts "이미지 다운로드 완료: #{selected_url}"
1002
+
1003
+ rescue => e
1004
+ retry_count += 1
1005
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
1006
+ sleep(3)
1007
+ if retry_count < max_retries
965
1008
  retry
1009
+ else
1010
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
1011
+
1012
+ if results && !results.empty?
1013
+ random_photo = results.sample
1014
+ fallback_url = random_photo.dig('urls', 'full')
1015
+ if fallback_url
1016
+ Down.download(fallback_url, destination: "./image/memory.png")
1017
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
1018
+ else
1019
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
1020
+ color_image
1021
+ end
1022
+ else
1023
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
1024
+ color_image
1025
+ end
1026
+ end
966
1027
  end
967
1028
  end
968
1029
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiupd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-01 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: mymin26@naver.com