nblog_duo 0.0.51 → 0.0.55

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/nblog_duo.rb +345 -218
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df7330c7c5e6074749a42ee6e4afc6fb0f07e36214a56bff8baa4f6141cf6e8c
4
- data.tar.gz: dce315107d0d30802e157960cb26c93a0d89b5c765febcc2083acd1104d579d3
3
+ metadata.gz: 398dd3e77cc0d829473c76405153daa2f032f5f3ee16a7ede96ffd178d3de231
4
+ data.tar.gz: d93f4a474d8c60449db041bcd23076ae4812da9cbf07f969fa855d010ad45970
5
5
  SHA512:
6
- metadata.gz: 9306802a0d0cf35c4cc2f22f95362b29b443f8add62dbb30dae08091f9607f7e9c5e1eaeb984695c10b99eac056eb1b2943abe1c90a563826a8abc7315b47bb9
7
- data.tar.gz: 6d0a34873d722d42f66ece97ba1bc0ca9f308e2f3741f32ec9ef888fbe834632dd778648e60a371dd91c331aedea322ad87bf7c6ad708c9694152e88ffaf4e9b
6
+ metadata.gz: 71a36c830723a73578cb68eda97403aa2b2d237fa9ea803169a2e9d1f2b288a524a7f51e78785c15ed582e77ce00741d0d92fa410ff97abe077ab98e13944d56
7
+ data.tar.gz: 428e7af6345dfa93cd7b9e3e798ed9111aa57c659e0ca6f6e319f0b3493e5bc86bb9b6251a00543ba2758ff379cd3a889a467ec5e9a9ec00cf251f9d012940d1
data/lib/nblog_duo.rb CHANGED
@@ -205,11 +205,14 @@ class Naver
205
205
  def initialize
206
206
  @seed = 1
207
207
  end
208
- def chrome_setup(user_id)
208
+ def chrome_setup(user_id, proxy)
209
209
  naver_cookie_dir = "C:/naver_cookie"
210
210
  FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
211
+ if proxy == ''
211
212
  system(%{"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" https://naver.com/ --remote-debugging-port=9222 --user-data-dir=C:/naver_cookie/#{user_id}})
212
-
213
+ else
214
+ system(%{"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" "https://naver.com/" --remote-debugging-port=9222 --user-data-dir=C:/naver_cookie/#{user_id} --proxy-server=#{proxy.to_s.force_encoding('utf-8').to_s}})
215
+ end
213
216
  end
214
217
  def chrome_start(proxy, user_id)
215
218
  naver_cookie_dir = "C:/naver_cookie"
@@ -290,7 +293,7 @@ class Naver
290
293
  end
291
294
 
292
295
  # 새로운 스레드 생성 및 실행
293
- Thread.new { chrome_setup(user_id) }
296
+ Thread.new { chrome_setup(user_id, proxy) }
294
297
  sleep(3)
295
298
 
296
299
 
@@ -744,58 +747,182 @@ class Naver
744
747
  path = URI.decode_www_form(path)[0][0]
745
748
  if option['라이브러리사용안함'] == 'true'
746
749
  # 현재 탭의 URL을 가져오기
747
-
750
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
748
751
  posting_url = @driver.current_url
749
752
  @driver.execute_script("window.open('#{posting_url}');")
750
753
  sleep(1)
751
754
  @driver.switch_to.window(@driver.window_handles[1])
752
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
753
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
754
- @driver.switch_to.frame(iframe)
755
755
  begin
756
- wait = Selenium::WebDriver::Wait.new(:timeout => 7)
757
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
758
- @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
756
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
757
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
758
+ @driver.switch_to.frame(iframe)
759
+ begin
760
+ wait = Selenium::WebDriver::Wait.new(:timeout => 7)
761
+ wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
762
+ @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
763
+ sleep(1)
764
+ rescue
765
+ end
766
+ @driver.execute_script(<<~JS)
767
+ window.URL.createObjectURL = function() {};
768
+ HTMLInputElement.prototype.click = function() {
769
+ console.log("File dialog suppressed");
770
+ };
771
+ JS
759
772
  sleep(1)
760
- rescue
761
- end
762
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
763
- sleep(1)
764
- Clipboard.copy(path.split('/').join("\\"))
765
- key_down('ctrl')
766
- key_stroke('v')
767
- key_up('ctrl')
768
- sleep(1)
769
- key_stroke('enter')
770
- sleep(2)
771
- @driver.action.send_keys(:up).perform
772
- sleep(1)
773
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
774
- sleep(1)
775
- @driver.switch_to.default_content()
776
- @driver.close
777
- sleep(1)
778
- @driver.switch_to.window(@driver.window_handles[0])
779
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
780
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
781
- @driver.switch_to.frame(iframe)
782
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
783
- key_down('ctrl')
784
- key_stroke('v')
785
- key_up('ctrl')
786
- sleep(1)
773
+
774
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
775
+ # 요소가 나타날 때까지 기다립니다.
776
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
777
+ # 해당 버튼을 찾고 클릭
778
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
779
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
780
+ sleep(1)
781
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
782
+ sleep(1)
783
+
784
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
785
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
786
+ sleep(1)
787
+ # 파일 입력 필드 찾기 (input[type="file"])
788
+ file_input = @driver.find_element(:id, 'hidden-file')
789
+ sleep(1)
790
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
791
+ file_input.send_keys(file_path)
792
+ sleep(3)
793
+ @driver.action.key_down(:up).key_up(:up).perform
794
+ sleep(1)
795
+
796
+ begin
797
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
798
+ #요소가 나타날 때까지 60초 동안 기다립니다.
799
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
800
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
801
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
802
+ sleep(1)
803
+ aria_expanded = element.attribute('aria-expanded')
804
+ if aria_expanded == 'false'
805
+ element.click
806
+ sleep(1) # 클릭 후 잠시 대기
807
+ else
808
+ end
809
+
810
+ begin
811
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
812
+ #요소가 나타날 때까지 60초 동안 기다립니다.
813
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
814
+ sleep(1)
815
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
816
+ sleep(1)
817
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
818
+ sleep(1)
819
+ rescue
820
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
821
+ #요소가 나타날 때까지 60초 동안 기다립니다.
822
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
823
+ sleep(1)
824
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
825
+ sleep(1)
826
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
827
+ sleep(1)
828
+ end
829
+ rescue
830
+ @driver.action.key_down(:down).key_up(:down).perform
831
+ end
832
+ sleep(2)
833
+ @driver.action.send_keys(:up).perform
834
+ sleep(1)
835
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
836
+ sleep(1)
837
+ @driver.switch_to.default_content()
838
+ @driver.close
839
+ sleep(1)
840
+ @driver.switch_to.window(@driver.window_handles[0])
841
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
842
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
843
+ @driver.switch_to.frame(iframe)
844
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
845
+ sleep(1)
846
+ rescue => e
847
+ @driver.quit
848
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
849
+ return 0
850
+ end
787
851
 
788
852
  else
789
- #@driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
790
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
791
- sleep(2)
792
- Clipboard.copy(path.split('/').join("\\"))
793
- key_down('ctrl')
794
- key_stroke('v')
795
- key_up('ctrl')
853
+ @driver.execute_script(<<~JS)
854
+ window.URL.createObjectURL = function() {};
855
+ HTMLInputElement.prototype.click = function() {
856
+ console.log("File dialog suppressed");
857
+ };
858
+ JS
796
859
  sleep(1)
797
- key_stroke('enter')
798
- sleep(2)
860
+ begin
861
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
862
+ # 요소가 나타날 때까지 기다립니다.
863
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
864
+ # 해당 버튼을 찾고 클릭
865
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
866
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
867
+ sleep(1)
868
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
869
+ sleep(1)
870
+
871
+
872
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
873
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
874
+ sleep(1)
875
+ # 파일 입력 필드 찾기 (input[type="file"])
876
+ file_input = @driver.find_element(:id, 'hidden-file')
877
+ sleep(1)
878
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
879
+ file_input.send_keys(file_path)
880
+ sleep(3)
881
+ @driver.action.key_down(:up).key_up(:up).perform
882
+ sleep(1)
883
+
884
+ begin
885
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
886
+ #요소가 나타날 때까지 60초 동안 기다립니다.
887
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
888
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
889
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
890
+ sleep(1)
891
+ aria_expanded = element.attribute('aria-expanded')
892
+ if aria_expanded == 'false'
893
+ element.click
894
+ sleep(1) # 클릭 후 잠시 대기
895
+ else
896
+ end
897
+
898
+ begin
899
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
900
+ #요소가 나타날 때까지 60초 동안 기다립니다.
901
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
902
+ sleep(1)
903
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
904
+ sleep(1)
905
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
906
+ sleep(1)
907
+ rescue
908
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
909
+ #요소가 나타날 때까지 60초 동안 기다립니다.
910
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
911
+ sleep(1)
912
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
913
+ sleep(1)
914
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
915
+ sleep(1)
916
+ end
917
+ rescue
918
+ @driver.action.key_down(:down).key_up(:down).perform
919
+ end
920
+ rescue => e
921
+ @driver.close
922
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
923
+ return 0
924
+ end
925
+
799
926
  end
800
927
 
801
928
 
@@ -827,217 +954,217 @@ class Naver
827
954
  sleep(1)
828
955
  end
829
956
 
830
-
831
- # end
832
- # components_value['src'] = 'https://blogfiles.pstatic.net'+image_data['item']['url']+'?type=w1'
833
- # components_value['internalResource'] = true
834
- # components_value['represent'] = true
835
- # components_value['path'] = image_data['item']['url']
836
- # components_value['domain'] = "https://blogfiles.pstatic.net"
837
- # components_value['fileSize'] = image_data['item']['fileSize'].to_i
838
- # components_value['width'] = image_data['item']['width'].to_i
839
- # components_value['widthPercentage'] = 0
840
- # components_value['height'] = image_data['item']['height'].to_i
841
- # components_value['fileName'] = image_data['item']['fileName'].to_i
842
- # components_value['caption'] = nil
843
- # if i2.to_s.split('href="')[1] != nil
844
- # components_value['link'] = CGI.unescape(i2.to_s.split('href="')[1].split('"')[0])
845
- # end
846
- # components_value['format'] = 'normal'
847
- # components_value['displayFormat'] = 'normal'
848
- # components_value['imageLoaded'] = true
849
- # components_value['contentMode'] = 'fit'
850
- # components_value['origin'] = {
851
- # 'srcFrom' => 'local',
852
- # '@ctype' => 'imageOrigin'
853
- # }
854
- # components_value['@ctype'] = 'image'
957
+
855
958
  elsif i2.to_s.include?('<video')
856
959
  path = i2.to_s.split('src="')[1].split('"')[0]
857
960
  path = URI.decode_www_form(path)[0][0]
961
+ begin
962
+ @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
963
+ sleep(3)
964
+
965
+
966
+ @driver.execute_script(<<~JS)
967
+ window.URL.createObjectURL = function() {};
968
+ HTMLInputElement.prototype.click = function() {
969
+ console.log("File dialog suppressed");
970
+ };
971
+ JS
972
+ sleep(1)
973
+ # 파일 업로드 버튼 클릭 (이제 파일 선택 창이 뜨지 않음)
974
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
975
+ sleep(3)
976
+
977
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
978
+ sleep(1)
979
+ # 파일 입력 필드 찾기 (input[type="file"])
980
+ file_input = @driver.find_element(:id, "hidden-input")
981
+ sleep(1)
982
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
983
+ file_input.send_keys(file_path)
984
+ sleep(3)
985
+
986
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
987
+ sleep(1)
988
+
989
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_description"]').send_keys(title)
990
+ sleep(1)
991
+
992
+
993
+
994
+
995
+ tags2 = option['tag'].to_s
996
+ tag_mm2 = Array.new
997
+ tags2.split(',').each do |tag_value|
998
+ tag_mm2 << ''+tag_value
999
+ end
1000
+
1001
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_tag"]').send_keys(tag_mm2.join("\n")+"\n")
1002
+ sleep(1)
1003
+
858
1004
 
859
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
860
- sleep(3)
861
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
862
- sleep(3)
863
-
864
- Clipboard.copy(path.split('/').join("\\"))
865
- key_down('ctrl')
866
- key_stroke('v')
867
- key_up('ctrl')
868
- sleep(3)
869
- key_stroke('enter')
870
- sleep(3)
871
-
872
- for n in 1..10
873
- puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
874
- if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
875
- break
1005
+ for n in 1..10
1006
+ begin
1007
+ puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
1008
+ if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
1009
+ break
1010
+ end
1011
+ sleep(10)
1012
+ rescue
1013
+ end
876
1014
  end
877
- sleep(10)
1015
+
1016
+
1017
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
1018
+ sleep(3)
1019
+ rescue => e
1020
+ @driver.close
1021
+ puts '동영상 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1022
+ return 0
878
1023
  end
879
- @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
880
- sleep(5)
881
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
882
- sleep(3)
883
-
884
1024
 
885
1025
  elsif i2.to_s.include?('<slide')
886
1026
  if option['라이브러리사용안함'] == 'true'
887
-
1027
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
888
1028
  posting_url = @driver.current_url
889
1029
  @driver.execute_script("window.open('#{posting_url}');")
890
1030
  sleep(1)
891
- @driver.switch_to.window(@driver.window_handles[1])
892
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
893
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
894
- @driver.switch_to.frame(iframe)
1031
+
895
1032
  begin
1033
+ @driver.switch_to.window(@driver.window_handles[1])
1034
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1035
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1036
+ @driver.switch_to.frame(iframe)
1037
+
1038
+
896
1039
  wait = Selenium::WebDriver::Wait.new(:timeout => 7)
897
1040
  wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
898
1041
  @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
899
1042
  sleep(1)
900
- rescue
901
- end
902
-
903
- slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
904
- paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
1043
+
905
1044
 
906
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
907
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
1045
+ @driver.execute_script(<<~JS)
1046
+ window.URL.createObjectURL = function() {};
1047
+ HTMLInputElement.prototype.click = function() {
1048
+ console.log("File dialog suppressed");
1049
+ };
1050
+ JS
1051
+ sleep(1)
1052
+ # 기다릴 시간 설정
908
1053
 
909
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
910
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
911
- # 3. 전체 경로를 클립보드에 복사
912
- Clipboard.copy(paths_with_quotes)
1054
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1055
+ # 요소가 나타날 때까지 기다립니다.
1056
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1057
+ # 해당 버튼을 찾고 클릭
1058
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1059
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1060
+ sleep(1)
1061
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1062
+ sleep(2)
1063
+
1064
+ slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
913
1065
 
914
- # 4. 전체 경로를 붙여넣기
915
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
916
- sleep(1)
917
-
918
- key_down('ctrl')
919
- key_stroke('v')
920
- key_up('ctrl')
921
- sleep(1)
922
- key_stroke('enter')
923
- sleep(2)
924
- #@driver.action.key_down(:control).send_keys('z').key_up(:control).perform
925
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1066
+ # 1. 큰따옴표로 감싸진 경로 추출
1067
+ paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
926
1068
 
927
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
928
- Clipboard.copy(image_names)
929
-
930
- # 8. 이미지 이름만 클립보드에 복사 붙여넣기
931
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
932
- sleep(1)
933
- sleep(1)
934
- key_down('ctrl')
935
- key_stroke('v')
936
- key_up('ctrl')
937
- sleep(1)
938
- key_stroke('enter')
939
- sleep(2)
940
-
941
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
942
- wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
943
- @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
944
- sleep(1)
945
- @driver.action.send_keys(:up).perform
946
- sleep(1)
947
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
948
- wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
949
- @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
950
- sleep(1)
1069
+ # 2. 경로를 윈도우 형식으로 변경
1070
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1071
+
1072
+ # 3. 여러 경로를 번에 전달할 수 있도록 줄바꿈으로 구분
1073
+ file_input = @driver.find_element(:id, 'hidden-file')
1074
+ sleep(1)
1075
+
1076
+ # 여러 파일 경로를 한 줄로 이어서 전달
1077
+ file_input.send_keys(image_paths.join("\n"))
1078
+ sleep(3)
1079
+
1080
+
951
1081
 
1082
+
1083
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1084
+ wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1085
+ @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1086
+ sleep(1)
1087
+ @driver.action.send_keys(:up).perform
1088
+ sleep(1)
1089
+
952
1090
 
953
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
954
- @driver.switch_to.default_content()
955
- @driver.close
956
- sleep(1)
957
- @driver.switch_to.window(@driver.window_handles[0])
958
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
959
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
960
- @driver.switch_to.frame(iframe)
961
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
962
- key_down('ctrl')
963
- key_stroke('v')
964
- key_up('ctrl')
965
- sleep(1)
1091
+
1092
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1093
+ wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1094
+ @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1095
+ sleep(1)
1096
+
1097
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
1098
+ @driver.switch_to.default_content()
1099
+ @driver.close
1100
+ sleep(1)
1101
+ @driver.switch_to.window(@driver.window_handles[0])
1102
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1103
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1104
+ @driver.switch_to.frame(iframe)
1105
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
1106
+ rescue => e
1107
+ @driver.quit
1108
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1109
+ return 0
1110
+ end
1111
+
966
1112
 
967
1113
  else
968
-
1114
+ @driver.execute_script(<<~JS)
1115
+ window.URL.createObjectURL = function() {};
1116
+ HTMLInputElement.prototype.click = function() {
1117
+ console.log("File dialog suppressed");
1118
+ };
1119
+ JS
1120
+ sleep(1)
1121
+ begin
1122
+ # 기다릴 시간 설정
1123
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1124
+ # 요소가 나타날 때까지 기다립니다.
1125
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1126
+ # 해당 버튼을 찾고 클릭
1127
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1128
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1129
+ sleep(1)
1130
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1131
+ sleep(2)
1132
+
969
1133
  slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
1134
+
1135
+ # 1. 큰따옴표로 감싸진 경로 추출
970
1136
  paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
971
-
972
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
973
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
974
-
975
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
976
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
977
- # 3. 전체 경로를 클립보드에 복사
978
- Clipboard.copy(paths_with_quotes)
979
1137
 
980
- # 4. 전체 경로를 붙여넣기
981
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
982
- sleep(1)
983
-
984
- key_down('ctrl')
985
- key_stroke('v')
986
- key_up('ctrl')
1138
+ # 2. 경로를 윈도우 형식으로 변경
1139
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1140
+
1141
+ # 3. 여러 경로를 한 번에 전달할 수 있도록 줄바꿈으로 구분
1142
+ file_input = @driver.find_element(:id, 'hidden-file')
987
1143
  sleep(1)
988
- key_stroke('enter')
989
- sleep(2)
990
-
991
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
992
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]') }
993
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1144
+
1145
+ # 여러 파일 경로를 한 줄로 이어서 전달
1146
+ file_input.send_keys(image_paths.join("\n"))
1147
+ sleep(3)
994
1148
 
995
-
996
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
997
- Clipboard.copy(image_names)
998
-
999
- # 8. 이미지 이름만 클립보드에 복사 후 붙여넣기
1000
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
1001
- sleep(1)
1002
- sleep(1)
1003
- key_down('ctrl')
1004
- key_stroke('v')
1005
- key_up('ctrl')
1006
- sleep(1)
1007
- key_stroke('enter')
1008
- sleep(2)
1009
-
1010
1149
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1011
1150
  wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1012
1151
  @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1013
1152
  sleep(1)
1014
1153
  @driver.action.send_keys(:up).perform
1015
1154
  sleep(1)
1016
-
1155
+
1017
1156
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1018
1157
  wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1019
1158
  @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1020
1159
  sleep(1)
1021
1160
  @driver.action.key_down(:enter).key_up(:enter).perform
1022
-
1023
-
1024
- end
1025
-
1026
-
1027
-
1028
-
1029
-
1030
-
1031
-
1032
-
1033
-
1034
-
1035
-
1036
-
1037
-
1038
-
1039
-
1040
-
1161
+ rescue => e
1162
+ @driver.close
1163
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1164
+ return 0
1165
+ end
1166
+
1167
+ end
1041
1168
 
1042
1169
 
1043
1170
 
@@ -3137,7 +3264,7 @@ class Wordpress
3137
3264
  @data['table'].pop
3138
3265
 
3139
3266
  dd_time = @data['table'][index][10].to_s.force_encoding('utf-8').to_i
3140
- template_no = @data['table'][index][7].to_s.force_encoding('utf-8').to_i
3267
+ #template_no = @data['table'][index][7].to_s.force_encoding('utf-8').to_i
3141
3268
  naver.update(title,content,option,soosick_1,soosick_2, dd_time)
3142
3269
 
3143
3270
 
@@ -3531,7 +3658,7 @@ class Wordpress
3531
3658
  i3 = i.to_s.force_encoding('utf-8').to_s
3532
3659
  i2 = i3.split(',')
3533
3660
  @data['table'] << [false, i2[0].to_s, i2[1].to_s,i2[2].to_s,i2[3].to_s,i2[4].to_s,i2[5].to_s,i2[6].to_s, 1,1,1,0,0]
3534
- @data['table'] << [false, i2[0].to_s, i2[1].to_s,i2[2].to_s,i2[3].to_s,i2[4].to_s,i2[5].to_s,i2[6].to_s, 1,1,1,0,0]
3661
+ @data['table'] << [false, i2[0].to_s, i2[1].to_s, 1,1,1,0,0]
3535
3662
  @data['table'].pop
3536
3663
  end
3537
3664
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nblog_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.51
4
+ version: 0.0.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-20 00:00:00.000000000 Z
11
+ date: 2025-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: File to Clipboard gem
14
14
  email: mymin26@naver.com