tiupz 0.0.2 → 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 +96 -35
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77c0d9b620f2e12aee1eebffb6cb503e07dd7e32fc8123508f465a85d457811f
4
- data.tar.gz: bb40055c37705c3ed6c9e87409e0fcabac4a0a5c34d086265d5895bbf4bd91c2
3
+ metadata.gz: e22c4dad9a12fef48d4798acc5f19ae52049f36b2a60f8ea9566adc0193fcede
4
+ data.tar.gz: a50e7ce90fca721f1409eb125dcc1bed6190892395f6189707dac89a9b1ccc18
5
5
  SHA512:
6
- metadata.gz: 2805d6eeed18a9fbd03a02e293c40fdcbed4e68f5adf9d12bb4e0e539165bdc997c27e8d34d35b1eedc8908dd70f11ef2e60f5ea3e26e5d16730a869825aed64
7
- data.tar.gz: 14ca55617826b91c792e6b9c7c93d62106733693304d36d302f3552f318b87def0bd546f8f9592f1d0e0a627745f719e13d43b133be270433f79161bec409a89
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
 
@@ -2312,33 +2373,33 @@ end
2312
2373
  button(' 폴더째로 불러오기 ') {
2313
2374
 
2314
2375
  on_clicked {
2315
- begin
2316
- path = @data['디엠설정']['폴더경로'].text.to_s.force_encoding('utf-8').force_encoding('utf-8')
2317
-
2318
- if Dir.exists?(path) # 경로가 존재하는지 확인
2319
- Dir.entries(path).each do |file|
2320
- # '.' '..'을 제외한 파일들만 처리
2321
- if file != '.' and file != '..'
2322
- begin
2323
- file_data = File.open(path+'/'+file, 'r', encoding: 'utf-8').read()
2324
- @data['디엠설정']['내용'] << [false, file, file_data]
2325
- rescue => e
2326
- # 파일 열기 오류 처리
2327
- puts "파일 '#{file}'을 열 수 없습니다: #{e.message}"
2328
- end
2376
+ path = @data['디엠설정']['폴더경로'].text.to_s.force_encoding('utf-8').force_encoding('utf-8')
2377
+
2378
+ # 경로가 유효한지 확인
2379
+ if Dir.exist?(path)
2380
+ Dir.entries(path).each do |file|
2381
+ if file == '.' or file == '..'
2382
+ next
2383
+ else
2384
+ begin
2385
+ # 파일을 열고 내용을 읽어서 추가
2386
+ file_data = File.open(path + '/' + file, 'r', encoding: 'utf-8').read
2387
+ @data['디엠설정']['디엠'] << [false, file, file_data]
2388
+ rescue => e
2389
+ # 파일을 열 수 없는 경우, 오류 메시지 출력
2390
+ puts "파일을 열 수 없습니다: #{file}, 오류: #{e.message}"
2329
2391
  end
2330
2392
  end
2331
- @data['디엠설정']['디엠'] << []
2332
- @data['디엠설정']['디엠'].pop
2333
- else
2334
- # 경로가 없으면 경고 메시지 출력
2335
- puts "경로 '#{path}'이 존재하지 않습니다."
2336
2393
  end
2337
- rescue => e
2338
- # 경로 처리 발생한 오류 처리
2339
- puts "오류 발생: #{e.message}"
2394
+
2395
+ # 내용 배열에서 마지막 항목 제거
2396
+ @data['디엠설정']['디엠'] << []
2397
+ @data['디엠설정']['디엠'].pop
2398
+ else
2399
+ # 경로가 유효하지 않을 경우, 오류 메시지 출력
2400
+ puts "경로가 존재하지 않습니다: #{path}"
2340
2401
  end
2341
- }
2402
+ }
2342
2403
  }
2343
2404
  }
2344
2405
  }
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.2
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-04-30 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