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.
- checksums.yaml +4 -4
- data/lib/tiupz.rb +96 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e22c4dad9a12fef48d4798acc5f19ae52049f36b2a60f8ea9566adc0193fcede
|
4
|
+
data.tar.gz: a50e7ce90fca721f1409eb125dcc1bed6190892395f6189707dac89a9b1ccc18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
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
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
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
|
-
|
2316
|
-
|
2317
|
-
|
2318
|
-
|
2319
|
-
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2323
|
-
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
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
|
-
|
2338
|
-
#
|
2339
|
-
|
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.
|
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-
|
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
|