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.
- checksums.yaml +4 -4
- data/lib/tiupd.rb +73 -12
- 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: 56b4f28660c4b6f5d64a447aade1fbc041026f28ddd65a055f9fef207b9d07ff
|
4
|
+
data.tar.gz: 3ab09b97e0363e3f79de0ea73f81f2352af84d6b59318a44c5aa0987844b1116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
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
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
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.
|
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-
|
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
|