tblog_zon 0.0.39 → 0.0.50
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/tblog_zon.rb +72 -11
- 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: 06d765fda4fbf3a4758df37b162e7275cfb67fcd6980f42d0bd97d1707ffd85a
|
4
|
+
data.tar.gz: eab1e8cc76c8f0e1af500b180a4bffcf835e384da8732dd1e9966190f49c10b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 835975aa79061c10dfca5b8dfe06baaeeb94ee5fbfa33b49bf540265d255cad84c07a5c95655bdbf3bc6cc925f331e53547ba7e0a4602b64d8f86b0e7d67f0ff
|
7
|
+
data.tar.gz: 0a1439d23c400f2a3ae178cbaa870a38ba125cb65971fc8c489d56c6d5f51d189d972da9677745a127ffaced909a4890d041d48d32d6280f5e0669d88092c372
|
data/lib/tblog_zon.rb
CHANGED
@@ -15,6 +15,7 @@ require 'uri'
|
|
15
15
|
require 'cgi'
|
16
16
|
require 'auto_click'
|
17
17
|
require 'rainbow/refinement'
|
18
|
+
require 'httpclient'
|
18
19
|
include AutoClickMethods
|
19
20
|
using Rainbow
|
20
21
|
include Glimmer
|
@@ -1566,21 +1567,81 @@ class Wordpress
|
|
1566
1567
|
|
1567
1568
|
|
1568
1569
|
|
1569
|
-
def auto_image
|
1570
|
+
def auto_image(keyword = nil)
|
1571
|
+
keyword ||= @keyword
|
1572
|
+
puts "키워드: #{keyword}"
|
1573
|
+
|
1574
|
+
client = HTTPClient.new
|
1575
|
+
client.default_header = {
|
1576
|
+
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
|
1577
|
+
'(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
|
1578
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
1579
|
+
'Accept-Language' => 'en-US,en;q=0.9',
|
1580
|
+
'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
|
1581
|
+
'X-Requested-With' => 'XMLHttpRequest'
|
1582
|
+
}
|
1583
|
+
|
1584
|
+
retry_count = 0
|
1585
|
+
max_retries = 10
|
1586
|
+
results = []
|
1587
|
+
|
1570
1588
|
begin
|
1571
1589
|
page = rand(1..15)
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1590
|
+
url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
|
1591
|
+
puts "Request URL: #{url}"
|
1592
|
+
res = client.get(url)
|
1593
|
+
|
1594
|
+
unless res.status == 200
|
1595
|
+
puts "HTTP Error: #{res.status}"
|
1596
|
+
raise "HTTP Error"
|
1577
1597
|
end
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1598
|
+
|
1599
|
+
json = JSON.parse(res.body)
|
1600
|
+
results = json['results']
|
1601
|
+
mm = []
|
1602
|
+
|
1603
|
+
results.each do |photo|
|
1604
|
+
full_url = photo.dig('urls', 'full').to_s
|
1605
|
+
regular_url = photo.dig('urls', 'regular').to_s
|
1606
|
+
|
1607
|
+
if full_url.start_with?("https://images.unsplash.com/photo-") &&
|
1608
|
+
regular_url.include?("1080")
|
1609
|
+
mm << full_url
|
1610
|
+
end
|
1611
|
+
end
|
1612
|
+
|
1613
|
+
if mm.empty?
|
1614
|
+
raise "No matching image"
|
1615
|
+
end
|
1616
|
+
|
1617
|
+
selected_url = mm.sample
|
1618
|
+
Down.download(selected_url, destination: "./image/memory.png")
|
1619
|
+
puts "이미지 다운로드 완료: #{selected_url}"
|
1620
|
+
|
1621
|
+
rescue => e
|
1622
|
+
retry_count += 1
|
1623
|
+
puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
|
1624
|
+
sleep(3)
|
1625
|
+
if retry_count < max_retries
|
1583
1626
|
retry
|
1627
|
+
else
|
1628
|
+
puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
|
1629
|
+
|
1630
|
+
if results && !results.empty?
|
1631
|
+
random_photo = results.sample
|
1632
|
+
fallback_url = random_photo.dig('urls', 'full')
|
1633
|
+
if fallback_url
|
1634
|
+
Down.download(fallback_url, destination: "./image/memory.png")
|
1635
|
+
puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
|
1636
|
+
else
|
1637
|
+
puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
|
1638
|
+
color_image
|
1639
|
+
end
|
1640
|
+
else
|
1641
|
+
puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
|
1642
|
+
color_image
|
1643
|
+
end
|
1644
|
+
end
|
1584
1645
|
end
|
1585
1646
|
end
|
1586
1647
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tblog_zon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.50
|
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
|