tiupz 0.0.3 → 0.0.6

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 +103 -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: b28a35ddecb58bc81eab2e685e381e9ee28c4fa840e55b0a1eb89fe8c645f075
4
+ data.tar.gz: 91cbf2a5676c180170da21d9f0cba2c42443d67b6bde642102337142a551d2ae
5
5
  SHA512:
6
- metadata.gz: d4951798671d491b077e36e3e3f59d185f69cc0b7937b718fbebaf67ca097ddc3bc95692ea2af9f38ed2e4716afa4007f87f960f5c54855b29a37c921a9f3821
7
- data.tar.gz: 8af9095db421249b5fe1dd53c6572229b43e562ad318cfedd3502d6f2ef53a1f80ff1cb99f7595888162450ae26102193df27e8f63464dbfb1614a3412f260c7
6
+ metadata.gz: ed792cbed060c8b973c44803c151143f97f2d2df317b228f518b1b7fbedf26833a276f114deb3b28a0c6ed6e6961feec57807710547f90faccc5bc3fb3cafa78
7
+ data.tar.gz: 00d1508b7fb964177131a13ac73fea1fb3c3dff3110ee0d305eb62e4c15a44a4ff4a8db934ae5e4f04a79e111f2c1406e8fc991b3bb4c448c908d6bd47a4c23c
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
@@ -24,7 +25,37 @@ class Naver
24
25
  def initialize(data)
25
26
  @data = data # Wordpress에서 전달된 data 저장
26
27
  @seed = 1
28
+ kill_selenium_chrome #기존 창 모두 닫는 명령
29
+ sleep(1)
27
30
  end
31
+
32
+ def kill_selenium_chrome #기존 창 모두 닫는 코드
33
+ wmi = WIN32OLE.connect("winmgmts://")
34
+ chrome_procs = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'chrome.exe'")
35
+
36
+ chrome_procs.each do |proc|
37
+ cmd = proc.CommandLine
38
+ if cmd && cmd.include?("user-data-dir=C:/tiktok_cookie")
39
+ puts "→ 크롬 창 초기화: PID #{proc.ProcessId}"
40
+ begin
41
+ proc.Terminate
42
+ rescue
43
+ #puts "→ 이미 종료된 프로세스: #{proc.ProcessId}"
44
+ end
45
+ end
46
+ end
47
+
48
+ # chromedriver도 같이 종료
49
+ chromedrivers = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'chromedriver.exe'")
50
+ chromedrivers.each do |proc|
51
+ puts "→ 크롬 창 초기화: PID #{proc.ProcessId}"
52
+ begin
53
+ proc.Terminate
54
+ rescue
55
+ #puts "→ 이미 종료된 chromedriver: #{proc.ProcessId}"
56
+ end
57
+ end
58
+ end
28
59
 
29
60
 
30
61
  def chrome_setup(user_id, proxy)
@@ -875,21 +906,81 @@ end
875
906
 
876
907
 
877
908
 
878
- def auto_image
909
+ def auto_image(keyword = nil)
910
+ keyword ||= @keyword
911
+ puts "키워드: #{keyword}"
912
+
913
+ client = HTTPClient.new
914
+ client.default_header = {
915
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
916
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
917
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
918
+ 'Accept-Language' => 'en-US,en;q=0.9',
919
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
920
+ 'X-Requested-With' => 'XMLHttpRequest'
921
+ }
922
+
923
+ retry_count = 0
924
+ max_retries = 10
925
+ results = []
926
+
879
927
  begin
880
928
  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']
929
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
930
+ puts "Request URL: #{url}"
931
+ res = client.get(url)
932
+
933
+ unless res.status == 200
934
+ puts "HTTP Error: #{res.status}"
935
+ raise "HTTP Error"
886
936
  end
887
- url = mm.sample
888
- Down.download(url, destination: "./image/memory.png")
889
- rescue
890
- puts 'auto_image 일시적 error 5초후 제시도...'
891
- sleep(5)
937
+
938
+ json = JSON.parse(res.body)
939
+ results = json['results']
940
+ mm = []
941
+
942
+ results.each do |photo|
943
+ full_url = photo.dig('urls', 'full').to_s
944
+ regular_url = photo.dig('urls', 'regular').to_s
945
+
946
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
947
+ regular_url.include?("1080")
948
+ mm << full_url
949
+ end
950
+ end
951
+
952
+ if mm.empty?
953
+ raise "No matching image"
954
+ end
955
+
956
+ selected_url = mm.sample
957
+ Down.download(selected_url, destination: "./image/memory.png")
958
+ puts "이미지 다운로드 완료: #{selected_url}"
959
+
960
+ rescue => e
961
+ retry_count += 1
962
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
963
+ sleep(3)
964
+ if retry_count < max_retries
892
965
  retry
966
+ else
967
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
968
+
969
+ if results && !results.empty?
970
+ random_photo = results.sample
971
+ fallback_url = random_photo.dig('urls', 'full')
972
+ if fallback_url
973
+ Down.download(fallback_url, destination: "./image/memory.png")
974
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
975
+ else
976
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
977
+ color_image
978
+ end
979
+ else
980
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
981
+ color_image
982
+ end
983
+ end
893
984
  end
894
985
  end
895
986
 
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.6
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-29 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: File to Clipboard gem
13
13
  email: mymin26@naver.com