tiupz 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/tiupz.rb +73 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc9dc0d55841892b1b11cc144c7889d5cdacec4357923482617734142f74ac0c
4
- data.tar.gz: f81655218442aa2c03db9de178b2bb7ff3d37ca6b8dad047305ffda9f7e3e2dc
3
+ metadata.gz: e22c4dad9a12fef48d4798acc5f19ae52049f36b2a60f8ea9566adc0193fcede
4
+ data.tar.gz: a50e7ce90fca721f1409eb125dcc1bed6190892395f6189707dac89a9b1ccc18
5
5
  SHA512:
6
- metadata.gz: d4951798671d491b077e36e3e3f59d185f69cc0b7937b718fbebaf67ca097ddc3bc95692ea2af9f38ed2e4716afa4007f87f960f5c54855b29a37c921a9f3821
7
- data.tar.gz: 8af9095db421249b5fe1dd53c6572229b43e562ad318cfedd3502d6f2ef53a1f80ff1cb99f7595888162450ae26102193df27e8f63464dbfb1614a3412f260c7
6
+ metadata.gz: 6f1820c3a2ea009d5292311327d2a4151ae6ff4e2f869ace425db4f4b4f4502eb2a5b9206a53fdd534c205b18d4f0fe2e37240c4b88ea136c8386008a1cd3400
7
+ data.tar.gz: db4798ac2d592cf8921bcf9465a04ed35012b437b021db7b58d7ced61ef3b4e297b2aa3032d67a2bf55fcceee2cabf81914abfa6e06263953a6d09f5c8b51856
data/lib/tiupz.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
@@ -875,21 +876,81 @@ end
875
876
 
876
877
 
877
878
 
878
- def auto_image
879
+ def auto_image(keyword = nil)
880
+ keyword ||= @keyword
881
+ puts "키워드: #{keyword}"
882
+
883
+ client = HTTPClient.new
884
+ client.default_header = {
885
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
886
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
887
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
888
+ 'Accept-Language' => 'en-US,en;q=0.9',
889
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
890
+ 'X-Requested-With' => 'XMLHttpRequest'
891
+ }
892
+
893
+ retry_count = 0
894
+ max_retries = 10
895
+ results = []
896
+
879
897
  begin
880
898
  page = rand(1..15)
881
- http = HTTP.get('https://unsplash.com/napi/photos?per_page=12&page='+page.to_s)
882
- json = JSON.parse(http.to_s)
883
- mm = Array.new
884
- json.each do |i|
885
- mm << i['urls']['full']
899
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
900
+ puts "Request URL: #{url}"
901
+ res = client.get(url)
902
+
903
+ unless res.status == 200
904
+ puts "HTTP Error: #{res.status}"
905
+ raise "HTTP Error"
886
906
  end
887
- url = mm.sample
888
- Down.download(url, destination: "./image/memory.png")
889
- rescue
890
- puts 'auto_image 일시적 error 5초후 제시도...'
891
- sleep(5)
907
+
908
+ json = JSON.parse(res.body)
909
+ results = json['results']
910
+ mm = []
911
+
912
+ results.each do |photo|
913
+ full_url = photo.dig('urls', 'full').to_s
914
+ regular_url = photo.dig('urls', 'regular').to_s
915
+
916
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
917
+ regular_url.include?("1080")
918
+ mm << full_url
919
+ end
920
+ end
921
+
922
+ if mm.empty?
923
+ raise "No matching image"
924
+ end
925
+
926
+ selected_url = mm.sample
927
+ Down.download(selected_url, destination: "./image/memory.png")
928
+ puts "이미지 다운로드 완료: #{selected_url}"
929
+
930
+ rescue => e
931
+ retry_count += 1
932
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
933
+ sleep(3)
934
+ if retry_count < max_retries
892
935
  retry
936
+ else
937
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
938
+
939
+ if results && !results.empty?
940
+ random_photo = results.sample
941
+ fallback_url = random_photo.dig('urls', 'full')
942
+ if fallback_url
943
+ Down.download(fallback_url, destination: "./image/memory.png")
944
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
945
+ else
946
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
947
+ color_image
948
+ end
949
+ else
950
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
951
+ color_image
952
+ end
953
+ end
893
954
  end
894
955
  end
895
956
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiupz
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