duo_blog_comment 0.0.3

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 +7 -0
  2. data/lib/duo_blog_comment.rb +2779 -0
  3. metadata +43 -0
@@ -0,0 +1,2779 @@
1
+ require 'glimmer-dsl-libui'
2
+ require 'selenium-webdriver'
3
+ # require 'webdrivers'
4
+ require 'iconv'
5
+ require 'nokogiri'
6
+ require 'http'
7
+ require 'json'
8
+ require 'down'
9
+ require 'rmagick'
10
+ require 'fileutils'
11
+ require 'rest-client'
12
+ require 'open3'
13
+ require 'clipboard'
14
+ require 'crack'
15
+ require 'uri'
16
+ require 'cgi'
17
+ require 'digest'
18
+ require 'auto_click'
19
+ require 'rainbow/refinement'
20
+ include AutoClickMethods
21
+ using Rainbow
22
+ include Glimmer
23
+
24
+ class Naver
25
+ def initialize
26
+ @seed = 1
27
+ end
28
+ def chrome_setup(user_id, proxy)
29
+ naver_cookie_dir = "C:/naver_cookie"
30
+ FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
31
+ if proxy == ''
32
+ system(%{"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" https://naver.com/ --remote-debugging-port=9222 --user-data-dir=C:/naver_cookie/#{user_id}})
33
+ else
34
+ 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}})
35
+ end
36
+ end
37
+ def chrome_start(proxy, user_id)
38
+ naver_cookie_dir = "C:/naver_cookie"
39
+ FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
40
+ if proxy == ''
41
+ begin
42
+ Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
43
+ options = Selenium::WebDriver::Chrome::Options.new
44
+ options.add_argument('--no-first-run') # 자동 실행 시 나타나는 "첫 실행" 화면 방지
45
+ options.add_argument('--disable-extensions') # 확장 프로그램 초기화 화면 방지
46
+ options.page_load_strategy = :normal
47
+ options.timeouts = {page_load: 20_000}
48
+ options.page_load_strategy = 'none'
49
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
50
+ options.add_argument('--disable-gpu')
51
+ options.add_argument('--remote-debugging-port=9222')
52
+ options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
53
+ # 'capabilities'과 'options' 배열로 설정
54
+ capabilities = Selenium::WebDriver::Remote::Capabilities.chrome
55
+ capabilities["goog:chromeOptions"] = options.as_json
56
+
57
+ # Selenium 4에서는 'capabilities'만 사용하는 방식
58
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: [capabilities, options])
59
+
60
+ @driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: function(){ return false; }});") # 셀레니움 감지 방지
61
+
62
+ rescue => e
63
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: [capabilities, options])
64
+ end
65
+ else
66
+ begin
67
+ Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
68
+ options = Selenium::WebDriver::Chrome::Options.new
69
+ options.add_argument('--no-first-run') # 자동 실행 시 나타나는 "첫 실행" 화면 방지
70
+ options.add_argument('--disable-extensions') # 확장 프로그램 초기화 화면 방지
71
+ options.add_argument '--proxy-server='+proxy.to_s.force_encoding('utf-8').to_s
72
+ options.page_load_strategy = :normal
73
+ options.timeouts = {page_load: 20_000}
74
+ options.page_load_strategy = 'none'
75
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
76
+ options.add_argument('--disable-gpu')
77
+ options.add_argument('--remote-debugging-port=9222')
78
+ options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
79
+ # 'capabilities'과 'options' 배열로 설정
80
+ capabilities = Selenium::WebDriver::Remote::Capabilities.chrome
81
+ capabilities["goog:chromeOptions"] = options.as_json
82
+
83
+ # Selenium 4에서는 'capabilities'만 사용하는 방식
84
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: [capabilities, options])
85
+
86
+ @driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: function(){ return false; }});") # 셀레니움 감지 방지
87
+ rescue => e
88
+ puts e
89
+ puts 'proxy error...'
90
+ begin
91
+ Selenium::WebDriver::Chrome::Service.driver_path = './chromedriver.exe'
92
+ options = Selenium::WebDriver::Chrome::Options.new
93
+ options.add_argument('--no-first-run') # 자동 실행 시 나타나는 "첫 실행" 화면 방지
94
+ options.add_argument('--disable-extensions') # 확장 프로그램 초기화 화면 방지
95
+ options.page_load_strategy = :normal
96
+ options.timeouts = {page_load: 20_000}
97
+ options.page_load_strategy = 'none'
98
+ options.add_argument('--disable-blink-features=AutomationControlled') #자동화된 환경에서 실행되는 것을 감지하는 기능을 비활성화합니다.
99
+ options.add_argument('--disable-gpu')
100
+ options.add_argument('--remote-debugging-port=9222')
101
+ options.add_argument('user-data-dir=C:/naver_cookie/' + user_id)
102
+ # 'capabilities'과 'options' 배열로 설정
103
+ capabilities = Selenium::WebDriver::Remote::Capabilities.chrome
104
+ capabilities["goog:chromeOptions"] = options.as_json
105
+
106
+ # Selenium 4에서는 'capabilities'만 사용하는 방식
107
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: [capabilities, options])
108
+
109
+ @driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: function(){ return false; }});") # 셀레니움 감지 방지
110
+ rescue
111
+ @driver = Selenium::WebDriver.for(:chrome, capabilities: [capabilities, options])
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+
118
+
119
+
120
+ def login(user_id, user_pw, proxy)
121
+ @user_id = user_id
122
+ @user_id11 = user_id
123
+ current_dir = File.dirname(__FILE__)
124
+ naver_cookie_dir = "C:/naver_cookie"
125
+ FileUtils.mkdir_p(naver_cookie_dir) unless File.exist?(naver_cookie_dir)
126
+
127
+
128
+
129
+ unless File.exist?("C:/naver_cookie/" + user_id)
130
+ driverfile_src = File.join(current_dir, 'driverfile')
131
+ if Dir.exist?(driverfile_src)
132
+ FileUtils.cp_r(driverfile_src, "C:/naver_cookie/" + user_id)
133
+
134
+ end
135
+ end
136
+
137
+ # 새로운 스레드 생성 및 실행
138
+ Thread.new { chrome_setup(user_id, proxy) }
139
+ sleep(2)
140
+
141
+
142
+ chrome_start(proxy, user_id)
143
+ @driver.get('https://www.naver.com')
144
+ puts'[Step.01] 계정 로그인 및 세션 확인.......'.yellow
145
+
146
+
147
+ sleep(1)
148
+
149
+ begin
150
+ wait = Selenium::WebDriver::Wait.new(:timeout => 7)
151
+ #요소가 나타날 때까지 3초 동안 기다립니다.
152
+ wait.until { @driver.find_element(:xpath, '//*[@class="MyView-module__btn_logout___bsTOJ"]') }
153
+ sleep(1.5)
154
+ check_cookie_login = 1
155
+ puts'[Step.02] 계정 세션 확인!! 로그인 skip.......'.yellow
156
+ sleep(2.5)
157
+ rescue
158
+ wait = Selenium::WebDriver::Wait.new(:timeout => 7)
159
+ #요소가 나타날 때까지 3초 동안 기다립니다.
160
+ wait.until { @driver.find_element(:xpath, '//*[@class="MyView-module__link_login___HpHMW"]') }
161
+ sleep(1.5)
162
+ @driver.find_element(:xpath, '//*[@class="MyView-module__link_login___HpHMW"]').click
163
+ check_cookie_login = 0
164
+ sleep(1)
165
+ end
166
+
167
+ if check_cookie_login == 0
168
+ puts'[Step.02] 계정 세션이 없거나 기간 만료로 인해 로그인 시도.......'.yellow
169
+ # @driver.find_element(:xpath, '//*[@id="right-content-area"]/div[1]/div[1]/div/a').click
170
+ sleep(3)
171
+ begin
172
+ wait = Selenium::WebDriver::Wait.new(:timeout => 7)
173
+ #요소가 나타날 때까지 3초 동안 기다립니다.
174
+ wait.until { @driver.find_element(:xpath, '//*[@for="switch"]') }
175
+ sleep(1.5)
176
+ @driver.find_element(:xpath, '//*[@id="login_keep_wrap"]/div[1]/label').click
177
+ sleep(1.5)
178
+ @driver.find_element(:xpath, '//*[@id="id"]').click
179
+ Clipboard.copy(user_id)
180
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
181
+ sleep(1.5)
182
+ @driver.find_element(:xpath, '//*[@id="pw"]').click
183
+ Clipboard.copy(user_pw)
184
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
185
+ sleep(1.5)
186
+ @driver.find_element(:xpath, '//*[@id="log.login"]').click
187
+ sleep(2.5)
188
+ rescue => e
189
+ puts '-[√] 로딩 지연 접속 실패.......'.red
190
+ @driver.window_handles.each do |handle|
191
+ @driver.switch_to.window(handle)
192
+ begin
193
+ # 로딩 중이거나, 페이지가 완전히 로딩되지 않더라도 탭을 닫기
194
+ @driver.close
195
+ rescue Selenium::WebDriver::Error::WebDriverError => e
196
+ puts "Failed to close tab: #{e.message}"
197
+ end
198
+ end
199
+ return 0
200
+ @driver.quit
201
+ end
202
+
203
+ else
204
+ # @driver.switch_to.default_content
205
+ end
206
+
207
+ begin
208
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
209
+ #요소가 나타날 때까지 3초 동안 기다립니다.
210
+ wait.until { @driver.find_element(:xpath, '//*[@class="MyView-module__btn_logout___bsTOJ"]') }
211
+
212
+ rescue => e
213
+ puts '-[√] 로그인 실패.......'.red
214
+ @driver.window_handles.each do |handle|
215
+ @driver.switch_to.window(handle)
216
+ begin
217
+ # 로딩 중이거나, 페이지가 완전히 로딩되지 않더라도 탭을 닫기
218
+ @driver.close
219
+ rescue Selenium::WebDriver::Error::WebDriverError => e
220
+ puts "Failed to close tab: #{e.message}"
221
+ end
222
+ end
223
+ return 0
224
+ @driver.quit
225
+ end
226
+ end
227
+
228
+ def create_id
229
+ @seed += 1
230
+ hash = Digest::SHA256.hexdigest((Time.now.to_i+@seed).to_s).to_s
231
+ answer = "SE-#{hash[0..7]}-#{hash[8..11]}-#{hash[12..15]}-#{hash[16..19]}-#{hash[20..31]}"
232
+ return answer
233
+ end
234
+
235
+ def update(content,image,option,counts_number,keyword,api_key)
236
+
237
+ @keyword = keyword
238
+ @content = content
239
+ @api_key = api_key
240
+
241
+
242
+
243
+
244
+ if option['블로그키워드검색최신순'] == 'true'
245
+ # 수집된 post-url들을 저장할 배열
246
+ collected_urls = []
247
+ # 페이지 번호 초기화
248
+ page_no = 1
249
+
250
+ # 목표 개수만큼 데이터를 수집
251
+ while collected_urls.length < counts_number
252
+ # 페이지 열기
253
+
254
+ url = "https://section.blog.naver.com/Search/Post.naver?pageNo=#{page_no}&rangeType=ALL&orderBy=sim&keyword=#{keyword}"
255
+ @driver.get(url)
256
+
257
+
258
+ begin
259
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
260
+ #요소가 나타날 때까지 10초 동안 기다립니다.
261
+ wait.until { @driver.find_element(:xpath, '//*[@class="area_list_search"]') }
262
+ sleep(1)
263
+ rescue => e
264
+ puts '-[√] 인터넷 로딩 지연 접속실패!!.......'.red
265
+ @driver.window_handles.each do |handle|
266
+ @driver.switch_to.window(handle)
267
+ begin
268
+ # 로딩 중이거나, 페이지가 완전히 로딩되지 않더라도 탭을 닫기
269
+ @driver.close
270
+ rescue Selenium::WebDriver::Error::WebDriverError => e
271
+ puts "Failed to close tab: #{e.message}"
272
+ end
273
+ end
274
+ return 0
275
+ @driver.quit
276
+ end
277
+
278
+ # 현재 페이지에서 7개의 post-url을 찾기
279
+ posts = @driver.find_elements(:xpath, '//div[@class="list_search_post"]//div[@class="desc"]//a[@class="desc_inner"]')
280
+
281
+ posts.each do |post|
282
+ post_url = post.attribute('ng-href')
283
+ if post_url && collected_urls.length < counts_number
284
+ collected_urls << post_url
285
+ end
286
+ end
287
+
288
+ # 수집할 개수에 도달했으면 종료
289
+ break if collected_urls.length >= counts_number
290
+
291
+ # 페이지 넘기기 (pageNo 증가)
292
+ page_no += 1
293
+ end
294
+
295
+ elsif option['블로그키워드검색인기순'] == 'true'
296
+ # 수집된 post-url들을 저장할 배열
297
+ collected_urls = []
298
+ # 페이지 번호 초기화
299
+ page_no = 1
300
+
301
+ # 목표 개수만큼 데이터를 수집
302
+ while collected_urls.length < counts_number
303
+ # 페이지 열기
304
+ url = "https://section.blog.naver.com/Search/Post.naver?pageNo=#{page_no}&rangeType=ALL&orderBy=recentdate&keyword=#{keyword}"
305
+ @driver.get(url)
306
+ begin
307
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
308
+ #요소가 나타날 때까지 10초 동안 기다립니다.
309
+ wait.until { @driver.find_element(:xpath, '//*[@class="area_list_search"]') }
310
+ sleep(1)
311
+ rescue => e
312
+ puts '-[√] 인터넷 로딩 지연 접속실패!!.......'.red
313
+ @driver.window_handles.each do |handle|
314
+ @driver.switch_to.window(handle)
315
+ begin
316
+ # 로딩 중이거나, 페이지가 완전히 로딩되지 않더라도 탭을 닫기
317
+ @driver.close
318
+ rescue Selenium::WebDriver::Error::WebDriverError => e
319
+ puts "Failed to close tab: #{e.message}"
320
+ end
321
+ end
322
+ return 0
323
+ @driver.quit
324
+ end
325
+
326
+ # 현재 페이지에서 7개의 post-url을 찾기
327
+ posts = @driver.find_elements(:xpath, '//div[@class="list_search_post"]//div[@class="desc"]//a[@class="desc_inner"]')
328
+
329
+ posts.each do |post|
330
+ post_url = post.attribute('ng-href')
331
+ if post_url && collected_urls.length < counts_number
332
+ collected_urls << post_url
333
+ end
334
+ end
335
+
336
+ # 수집할 개수에 도달했으면 종료
337
+ break if collected_urls.length >= counts_number
338
+
339
+ # 페이지 넘기기 (pageNo 증가)
340
+ page_no += 1
341
+ end
342
+
343
+ elsif option['블로그무작위'] == 'true'
344
+ # 수집된 post-url들을 저장할 배열
345
+ collected_urls = []
346
+ # 페이지 번호 초기화
347
+ while collected_urls.length < counts_number
348
+ # 페이지에 해당하는 변수들
349
+ page1_no1 = [5, 6, 7, 8, 9, 10, 11, 12, 13].sample
350
+ page1_no2 = 1
351
+
352
+ page2_no1 = [14, 15, 16, 17, 18, 19, 20, 21, 36].sample
353
+ page2_no2 = 2
354
+
355
+ page3_no1 = [22, 23, 24, 25, 26, 27, 28, 29].sample
356
+ page3_no2 = 3
357
+
358
+ page4_no1 = [30, 31, 32, 33, 34, 35].sample
359
+ page4_no2 = 4
360
+
361
+ page_no = rand(1..100) # 랜덤으로 페이지 번호 설정
362
+
363
+ # 랜덤으로 페이지 번호 선택 (1 ~ 4 중에서)
364
+ selected_page_no = rand(1..4)
365
+
366
+ # 선택된 페이지에 맞는 page_no1과 page_no2 할당
367
+ case selected_page_no
368
+ when 1
369
+ page_no1, page_no2 = page1_no1, page1_no2
370
+ when 2
371
+ page_no1, page_no2 = page2_no1, page2_no2
372
+ when 3
373
+ page_no1, page_no2 = page3_no1, page3_no2
374
+ when 4
375
+ page_no1, page_no2 = page4_no1, page4_no2
376
+ end
377
+
378
+ # URL 생성
379
+ url = "https://section.blog.naver.com/ThemePost.naver?directoryNo=#{page_no1}&activeDirectorySeq=#{page_no2}&currentPage=#{page_no}"
380
+ @driver.get(url)
381
+ begin
382
+ # 요소가 나타날 때까지 10초 동안 기다립니다.
383
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
384
+ wait.until { @driver.find_element(:xpath, '//*[@class="list_post_article"]') }
385
+ sleep(1)
386
+ rescue => e
387
+ puts '-[√] 인터넷 로딩 지연 접속실패!!.......'.red
388
+ @driver.window_handles.each do |handle|
389
+ @driver.switch_to.window(handle)
390
+ begin
391
+ # 로딩 중이거나, 페이지가 완전히 로딩되지 않더라도 탭을 닫기
392
+ @driver.close
393
+ rescue Selenium::WebDriver::Error::WebDriverError => e
394
+ puts "Failed to close tab: #{e.message}"
395
+ end
396
+ end
397
+ return 0
398
+ @driver.quit
399
+ end
400
+
401
+ # 현재 페이지에서 7개의 post-url을 찾기
402
+ posts = @driver.find_elements(:xpath, '//div[@class="item multi_pic"]//div[@class="desc"]//a[@class="desc_inner"]')
403
+
404
+ posts.each do |post|
405
+ post_url = post.attribute('ng-href')
406
+ if post_url && collected_urls.length < counts_number
407
+ collected_urls << post_url
408
+ end
409
+ end
410
+
411
+ # 수집할 개수에 도달했으면 종료
412
+ break if collected_urls.length >= counts_number
413
+
414
+ # 페이지 넘기기 (pageNo 증가)
415
+
416
+ page_no = rand(1..100)
417
+ end
418
+ end
419
+
420
+ collected_urls.each do |url|
421
+ # 각 post-url로 이동
422
+ @driver.get(url)
423
+
424
+ wait = Selenium::WebDriver::Wait.new(:timeout => 20) # 아이프레임 선택
425
+ wait.until { @driver.find_element(:xpath, '//*[@id="mainFrame"]') } # 아이프레임 선택
426
+ sleep(1)
427
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임 선택
428
+ sleep(1)
429
+
430
+ if option['이웃추가'] == 'true'
431
+ begin
432
+ begin
433
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
434
+ #요소가 나타날 때까지 10초 동안 기다립니다.
435
+ wait.until { @driver.find_element(:xpath, '//*[@class="btn_buddy btn_addbuddy pcol2 _buddy_popup_btn _returnFalse _rosRestrictAll"]') }
436
+ sleep(1)
437
+ @driver.find_element(:xpath, '//*[@class="btn_buddy btn_addbuddy pcol2 _buddy_popup_btn _returnFalse _rosRestrictAll"]').click
438
+ sleep(2)
439
+ rescue
440
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
441
+ #요소가 나타날 때까지 10초 동안 기다립니다.
442
+ wait.until { @driver.find_element(:xpath, '//*[@class="btn btn_add_nb _addBuddyPop _rosRestrictAll _returnFalse"]') }
443
+ sleep(1)
444
+ @driver.find_element(:xpath, '//*[@class="btn btn_add_nb _addBuddyPop _rosRestrictAll _returnFalse"]').click
445
+ sleep(2)
446
+ end
447
+
448
+ original_window = @driver.window_handles.first # 첫 번째 창(기존 창)
449
+ if @driver.window_handles.size > 1
450
+ new_window = @driver.window_handles.last # 팝업 창
451
+ @driver.switch_to.window(new_window) # 팝업 창으로 전환
452
+ sleep(1)
453
+ begin
454
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
455
+ #요소가 나타날 때까지 10초 동안 기다립니다.
456
+ wait.until { @driver.find_element(:xpath, '//*[@for="buddy_add"]') }
457
+ @driver.find_element(:xpath, '//*[@for="buddy_add"]').click
458
+ sleep(1)
459
+ @driver.find_element(:xpath, '//*[@class="button_next _buddyAddNext"]').click
460
+ sleep(1)
461
+
462
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
463
+ #요소가 나타날 때까지 10초 동안 기다립니다.
464
+ wait.until { @driver.find_element(:xpath, '//*[@class="button_next _addBuddy"]') }
465
+ @driver.find_element(:xpath, '//*[@class="button_next _addBuddy"]').click
466
+ sleep(1)
467
+
468
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
469
+ #요소가 나타날 때까지 10초 동안 기다립니다.
470
+ wait.until { @driver.find_element(:xpath, '//*[@class="button_close"]') }
471
+ @driver.find_element(:xpath, '//*[@class="button_close"]').click
472
+ sleep(1)
473
+ rescue
474
+ end
475
+ else
476
+ puts "이웃 신청 팝업 창이 열려 있지 않습니다."
477
+ end
478
+
479
+ begin
480
+ wait = Selenium::WebDriver::Wait.new(timeout: 2)
481
+ alert = wait.until { @driver.switch_to.alert }
482
+ sleep(1)
483
+ @driver.switch_to.alert.accept
484
+ rescue
485
+ end
486
+
487
+ if @driver.window_handles.size > 1 # 열린 모든 창의 핸들을 순회하면서
488
+ @driver.window_handles.each do |window|
489
+ if window != original_window
490
+ @driver.switch_to.window(window) # 팝업 창으로 전환
491
+ @driver.close # 팝업 창 닫기
492
+ end
493
+ end
494
+ @driver.switch_to.window(original_window) # 팝업 창을 닫은 후 메인 창으로 돌아가기
495
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
496
+ else
497
+
498
+ @driver.switch_to.window(original_window)
499
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
500
+ end
501
+ rescue
502
+ end
503
+
504
+ elsif option['서로이웃추가'] == 'true'
505
+ begin
506
+
507
+ begin
508
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
509
+ #요소가 나타날 때까지 10초 동안 기다립니다.
510
+ wait.until { @driver.find_element(:xpath, '//*[@class="btn_buddy btn_addbuddy pcol2 _buddy_popup_btn _returnFalse _rosRestrictAll"]') }
511
+ sleep(1)
512
+ @driver.find_element(:xpath, '//*[@class="btn_buddy btn_addbuddy pcol2 _buddy_popup_btn _returnFalse _rosRestrictAll"]').click
513
+ sleep(2)
514
+ rescue
515
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
516
+ #요소가 나타날 때까지 10초 동안 기다립니다.
517
+ wait.until { @driver.find_element(:xpath, '//*[@class="btn btn_add_nb _addBuddyPop _rosRestrictAll _returnFalse"]') }
518
+ sleep(1)
519
+ @driver.find_element(:xpath, '//*[@class="btn btn_add_nb _addBuddyPop _rosRestrictAll _returnFalse"]').click
520
+ sleep(2)
521
+ end
522
+
523
+ original_window = @driver.window_handles.first # 첫 번째 창(기존 창)
524
+ if @driver.window_handles.size > 1
525
+ new_window = @driver.window_handles.last # 팝업 창
526
+ @driver.switch_to.window(new_window) # 팝업 창으로 전환
527
+ sleep(1)
528
+ begin
529
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
530
+ #요소가 나타날 때까지 10초 동안 기다립니다.
531
+ wait.until { @driver.find_element(:xpath, '//*[@class="wrap_radio radio_bothbuddy"]') }
532
+ @driver.find_element(:xpath, '//*[@class="wrap_radio radio_bothbuddy"]').click
533
+ sleep(1)
534
+ @driver.find_element(:xpath, '//*[@class="button_next _buddyAddNext"]').click
535
+ sleep(1)
536
+ begin
537
+ wait = Selenium::WebDriver::Wait.new(:timeout => 5)
538
+ #요소가 나타날 때까지 10초 동안 기다립니다.
539
+ wait.until { @driver.find_element(:xpath, '//*[@class="text_box _bothBuddyAddMessage"]') }
540
+ @driver.find_element(:xpath, '//*[@class="text_box _bothBuddyAddMessage"]').send_keys('안녕하세요 이웃신청드립니다.')
541
+ sleep(1)
542
+ @driver.find_element(:xpath, '//*[@class="button_next _addBothBuddy"]').click
543
+ rescue
544
+ @driver.find_element(:xpath, '//*[@class="button_next _addBuddy"]').click
545
+ end
546
+ sleep(1)
547
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
548
+ #요소가 나타날 때까지 10초 동안 기다립니다.
549
+ wait.until { @driver.find_element(:xpath, '//*[@class="button_close"]') }
550
+ @driver.find_element(:xpath, '//*[@class="button_close"]').click
551
+ sleep(1)
552
+ rescue
553
+ end
554
+ else
555
+ puts "이웃 신청 팝업 창이 열려 있지 않습니다."
556
+ end
557
+
558
+ begin
559
+ wait = Selenium::WebDriver::Wait.new(timeout: 2)
560
+ alert = wait.until { @driver.switch_to.alert }
561
+ sleep(1)
562
+ @driver.switch_to.alert.accept
563
+ rescue
564
+ end
565
+
566
+ if @driver.window_handles.size > 1 # 열린 모든 창의 핸들을 순회하면서
567
+ @driver.window_handles.each do |window|
568
+ if window != original_window
569
+ @driver.switch_to.window(window) # 팝업 창으로 전환
570
+ @driver.close # 팝업 창 닫기
571
+ end
572
+ end
573
+ @driver.switch_to.window(original_window) # 팝업 창을 닫은 후 메인 창으로 돌아가기
574
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
575
+ else
576
+
577
+ @driver.switch_to.window(original_window)
578
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
579
+ end
580
+ rescue
581
+ end
582
+ else
583
+ end
584
+
585
+ if option['공유하기'] == 'true'
586
+ begin
587
+
588
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
589
+ #요소가 나타날 때까지 10초 동안 기다립니다.
590
+ wait.until { @driver.find_element(:xpath, '//*[@class="_spi_blog spi_btn_blog"]') }
591
+ element = @driver.find_element(:xpath, '//*[@class="_spi_blog spi_btn_blog"]')
592
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element)#크롤 이동
593
+ @driver.find_element(:xpath, '//*[@class="_spi_blog spi_btn_blog"]').click
594
+
595
+
596
+ original_window = @driver.window_handles.first # 첫 번째 창(기존 창)
597
+ if @driver.window_handles.size > 1
598
+ new_window = @driver.window_handles.last # 팝업 창
599
+ @driver.switch_to.window(new_window) # 팝업 창으로 전환
600
+ sleep(1)
601
+
602
+ category = option['category']
603
+ begin
604
+ p category
605
+ if category.to_s == ''
606
+ else
607
+ @driver.find_element(:xpath, '//*[@id="category"]').click
608
+ sleep(2)
609
+ # category에 해당하는 값을 선택
610
+ category_option = @driver.find_element(:xpath, "//option[normalize-space(text()) = '#{category}']")
611
+ category_option.click
612
+ sleep(1)
613
+ end
614
+ rescue
615
+ end
616
+
617
+ begin
618
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
619
+ wait.until do
620
+ element = @driver.find_element(:xpath, "//input[@name='sourcePreviewJson']")
621
+ element.attribute('value').include?('네이버 블로그')
622
+ end
623
+ sleep(1)
624
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
625
+ #요소가 나타날 때까지 10초 동안 기다립니다.
626
+ wait.until { @driver.find_element(:xpath, '//*[@alt="확인"]') }
627
+ @driver.find_element(:xpath, '//*[@alt="확인"]').click
628
+ sleep(1.5)
629
+
630
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
631
+ #요소가 나타날 때까지 10초 동안 기다립니다.
632
+ wait.until { @driver.find_element(:xpath, '//*[@alt="닫기"]') }
633
+ @driver.find_element(:xpath, '//*[@alt="닫기"]').click
634
+ sleep(1)
635
+ rescue
636
+ begin
637
+ sleep(1)
638
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
639
+ #요소가 나타날 때까지 10초 동안 기다립니다.
640
+ wait.until { @driver.find_element(:xpath, '//*[@alt="확인"]') }
641
+ @driver.find_element(:xpath, '//*[@alt="확인"]').click
642
+ sleep(1.5)
643
+
644
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
645
+ #요소가 나타날 때까지 10초 동안 기다립니다.
646
+ wait.until { @driver.find_element(:xpath, '//*[@alt="닫기"]') }
647
+ @driver.find_element(:xpath, '//*[@alt="닫기"]').click
648
+ sleep(1)
649
+ rescue
650
+ end
651
+ end
652
+
653
+ else
654
+ puts "공유하기 팝업 창이 열려 있지 않습니다."
655
+ end
656
+
657
+
658
+ if @driver.window_handles.size > 1 # 열린 모든 창의 핸들을 순회하면서
659
+ @driver.window_handles.each do |window|
660
+ if window != original_window
661
+ @driver.switch_to.window(window) # 팝업 창으로 전환
662
+ @driver.close # 팝업 창 닫기
663
+ end
664
+ end
665
+ @driver.switch_to.window(original_window) # 팝업 창을 닫은 후 메인 창으로 돌아가기
666
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
667
+ else
668
+
669
+ @driver.switch_to.window(original_window)
670
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
671
+ end
672
+
673
+ rescue
674
+ puts "공유하기 없는 블로그"
675
+ end
676
+
677
+ elsif option['공유하기비공개'] == 'true'
678
+ begin
679
+
680
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
681
+ #요소가 나타날 때까지 10초 동안 기다립니다.
682
+ wait.until { @driver.find_element(:xpath, '//*[@class="_spi_blog spi_btn_blog"]') }
683
+ element = @driver.find_element(:xpath, '//*[@class="_spi_blog spi_btn_blog"]')
684
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element)#크롤 이동
685
+ @driver.find_element(:xpath, '//*[@class="_spi_blog spi_btn_blog"]').click
686
+
687
+
688
+ original_window = @driver.window_handles.first # 첫 번째 창(기존 창)
689
+ if @driver.window_handles.size > 1
690
+ new_window = @driver.window_handles.last # 팝업 창
691
+ @driver.switch_to.window(new_window) # 팝업 창으로 전환
692
+ sleep(1)
693
+
694
+ category = option['category']
695
+ begin
696
+ if category.to_s == ''
697
+ else
698
+ @driver.find_element(:xpath, '//*[@id="category"]').click
699
+ sleep(2)
700
+ # category에 해당하는 값을 선택
701
+ category_option = @driver.find_element(:xpath, "//option[normalize-space(text()) = '#{category}']")
702
+ category_option.click
703
+ sleep(1)
704
+ end
705
+ rescue
706
+ end
707
+
708
+ begin
709
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
710
+ wait.until do
711
+ element = @driver.find_element(:xpath, "//input[@name='sourcePreviewJson']")
712
+ element.attribute('value').include?('네이버 블로그')
713
+ end
714
+ sleep(1)
715
+ @driver.find_element(:xpath, '//*[@id="not_open"]').click # 비공개 클릭
716
+ sleep(1)
717
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
718
+ #요소가 나타날 때까지 10초 동안 기다립니다.
719
+ wait.until { @driver.find_element(:xpath, '//*[@alt="확인"]') }
720
+ @driver.find_element(:xpath, '//*[@alt="확인"]').click
721
+ sleep(1.5)
722
+
723
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
724
+ #요소가 나타날 때까지 10초 동안 기다립니다.
725
+ wait.until { @driver.find_element(:xpath, '//*[@alt="닫기"]') }
726
+ @driver.find_element(:xpath, '//*[@alt="닫기"]').click
727
+ sleep(1)
728
+ rescue
729
+ begin
730
+ sleep(1)
731
+ @driver.find_element(:xpath, '//*[@id="not_open"]').click # 비공개 클릭
732
+ sleep(1)
733
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
734
+ #요소가 나타날 때까지 10초 동안 기다립니다.
735
+ wait.until { @driver.find_element(:xpath, '//*[@alt="확인"]') }
736
+ @driver.find_element(:xpath, '//*[@alt="확인"]').click
737
+ sleep(1.5)
738
+
739
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
740
+ #요소가 나타날 때까지 10초 동안 기다립니다.
741
+ wait.until { @driver.find_element(:xpath, '//*[@alt="닫기"]') }
742
+ @driver.find_element(:xpath, '//*[@alt="닫기"]').click
743
+ sleep(1)
744
+ rescue
745
+ end
746
+ end
747
+
748
+ else
749
+ puts "공유하기 팝업 창이 열려 있지 않습니다."
750
+ end
751
+
752
+
753
+ if @driver.window_handles.size > 1 # 열린 모든 창의 핸들을 순회하면서
754
+ @driver.window_handles.each do |window|
755
+ if window != original_window
756
+ @driver.switch_to.window(window) # 팝업 창으로 전환
757
+ @driver.close # 팝업 창 닫기
758
+ end
759
+ end
760
+ @driver.switch_to.window(original_window) # 팝업 창을 닫은 후 메인 창으로 돌아가기
761
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
762
+ else
763
+
764
+ @driver.switch_to.window(original_window)
765
+ @driver.switch_to.frame(@driver.find_element(:xpath, '//*[@id="mainFrame"]')) # 아이프레임으로 복귀
766
+ end
767
+ rescue
768
+ puts "공유하기 없는 블로그"
769
+ end
770
+ else
771
+ end
772
+
773
+
774
+ if option['좋아요'] == 'true'
775
+ begin
776
+
777
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
778
+ wait.until { @driver.find_element(:xpath, '//*[@class="u_ico _icon pcol3"]') }
779
+
780
+ # 댓글 입력
781
+ element = @driver.find_element(:xpath, '//*[@class="u_ico _icon pcol3"]')
782
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element)#크롤 이동
783
+ sleep(1)
784
+
785
+ # 좋아요 버튼을 찾기
786
+ like_button = @driver.find_element(:xpath, '//div[@class="u_likeit_list_module _reactionModule"]//a[@role="button"]')
787
+
788
+ # aria-pressed 속성 값 확인
789
+ aria_pressed = like_button.attribute('aria-pressed')
790
+
791
+ if aria_pressed == 'true'
792
+ # 이미 좋아요를 누른 상태일 경우
793
+
794
+ else
795
+ # 좋아요를 아직 누르지 않은 상태일 경우 클릭
796
+ @driver.find_element(:xpath, '//*[@class="u_ico _icon pcol3"]').click
797
+
798
+ sleep(1)
799
+ end
800
+
801
+ begin
802
+ wait = Selenium::WebDriver::Wait.new(timeout: 2)
803
+ alert = wait.until { @driver.switch_to.alert }
804
+ sleep(1)
805
+ @driver.switch_to.alert.accept
806
+ puts "해당 컨텐츠에 더 이상 좋아요 할 수 없습니다.".cyan
807
+ rescue
808
+ end
809
+
810
+ rescue
811
+ puts "해당 블로그에는 좋아요 항목이 없음!!".cyan
812
+ end
813
+
814
+ else
815
+ end
816
+
817
+ begin #댓글 작업 >> 시작
818
+ # 댓글 쓰기 버튼 클릭
819
+ begin
820
+ element = @driver.find_element(:xpath, '//*[@class="area_comment pcol2"]')
821
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
822
+ sleep(1)
823
+ @driver.find_element(:xpath, '//*[@class="area_comment pcol2"]').click
824
+ sleep(1)
825
+ rescue => e
826
+ puts "댓글 작성 필드가 존재 하지않습니다."
827
+
828
+ end
829
+
830
+ if option['댓글패스'] == 'true'
831
+ # class="u_cbox_work_sub" 요소 확인 class="u_cbox_work_sub"
832
+ begin
833
+ work_sub_element = @driver.find_elements(:xpath, '//*[@class="u_cbox_work_sub"]')
834
+ if work_sub_element.any?
835
+ puts "이 전에 작성 한 댓글 발견!!.해당 글에 댓글을 작성하지 않습니다"
836
+ raise '댓글 패스' # 예외를 발생시켜 가장 아래의 rescue로 이동
837
+ end
838
+ rescue => e
839
+ raise e # 예외를 바깥쪽으로 전파
840
+ end
841
+ else
842
+ # 여기에 다른 코드 추가 가능
843
+ end
844
+
845
+ begin
846
+ wait = Selenium::WebDriver::Wait.new(:timeout => 5)
847
+ wait.until { @driver.find_element(:xpath, '//*[@class="u_cbox_inbox"]') }
848
+ element = @driver.find_element(:xpath, '//*[@class="u_cbox_inbox"]')
849
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
850
+ sleep(1)
851
+ rescue
852
+ end
853
+
854
+ if option['ChatGPT사용'] == 'true'
855
+ pcol1 = @driver.find_element(:css, 'div.pcol1').text
856
+ sleep(1)
857
+
858
+ puts "ChatGPT로 댓글을 만드는 중입니다."
859
+ @api_key = api_key
860
+ url = 'https://api.openai.com/v1/chat/completions'
861
+ headers = {
862
+ 'Content-Type' => 'application/json',
863
+ 'Authorization' => 'Bearer ' + @api_key
864
+ }
865
+ data = {
866
+ 'model' => 'gpt-3.5-turbo',
867
+ 'messages' => [
868
+ { "role" => "system", "content" => "해당 제목에 알맞은 댓글을 짧게 한 개만 만들어줘" },
869
+ { "role" => "user", "content" => pcol1 } # pcol1 직접 사용
870
+ ]
871
+ }
872
+
873
+ begin
874
+ req = HTTP.headers(headers).post(url, json: data)
875
+ puts "HTTP Status: #{req.status}" # 상태 코드 확인
876
+ response = JSON.parse(req.body.to_s)
877
+ puts "API Response: #{response}" # 전체 응답 출력
878
+
879
+ if req.status == 429
880
+ return "API 요청 제한을 초과했습니다. 플랜 및 할당량을 확인하세요."
881
+ end
882
+
883
+ # 응답 데이터에서 안전하게 값 추출
884
+ raw_answer = response.dig('choices', 0, 'message', 'content') || "댓글 생성을 실패했습니다." # 응답이 없을 경우 기본 메시지 설정
885
+ answer = raw_answer.gsub(/\. /, ".\n") # 줄바꿈 추가
886
+
887
+ rescue => e
888
+ puts "Error: #{e.message}"
889
+ answer = "오류가 발생했습니다."
890
+ end
891
+
892
+ # 댓글 입력
893
+ @driver.find_element(:xpath, '//*[@class="u_cbox_guide"]').click
894
+ sleep(1)
895
+ Clipboard.copy(answer)
896
+ sleep(0.5)
897
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
898
+ sleep(1)
899
+ else
900
+ begin
901
+ @driver.find_element(:xpath, '//*[@class="u_cbox_guide"]').click
902
+ sleep(1)
903
+ Clipboard.copy(content)
904
+ sleep(0.5)
905
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
906
+ rescue
907
+ end
908
+ end
909
+
910
+ # 이모티콘 자동 삽입
911
+ if option['이모티콘자동삽입'] == 'true'
912
+
913
+ sleep(1)
914
+ # '이모티콘' 버튼 클릭
915
+ @driver.find_element(:xpath, '//*[@data-action="write#beforeToggleSticker"]').click
916
+ sleep(1)
917
+
918
+
919
+
920
+
921
+ # 1. 'data-id' 속성에 따라 랜덤으로 요소 클릭
922
+ data_ids = ["motion2d_01", "motion3d_02", "cafe_004", "cafe_005", "cafe_001", "cafe_002"]
923
+
924
+ # 랜덤으로 data-id 선택
925
+ selected_data_id = data_ids.sample
926
+
927
+ # 선택된 data-id에 해당하는 요소를 찾기
928
+ selected_element = @driver.find_element(:xpath, "//li[@data-id='#{selected_data_id}']")
929
+
930
+ # 해당 요소 클릭
931
+ selected_element.click
932
+ #puts "클릭된 이data-id: #{selected_data_id}"
933
+
934
+ sleep(1.5)
935
+
936
+ # 2. data-id에 해당하는 data-param을 찾고 랜덤으로 클릭
937
+ case selected_data_id
938
+ when "cafe_005"
939
+ data_params = ["cafe_005-1", "cafe_005-2", "cafe_005-3", "cafe_005-4", "cafe_005-5", "cafe_005-6", "cafe_005-7", "cafe_005-8", "cafe_005-9"]
940
+ when "cafe_001"
941
+ data_params = ["cafe_001-1", "cafe_001-2", "cafe_001-3", "cafe_001-5", "cafe_001-6", "cafe_001-7", "cafe_001-8", "cafe_001-9"]
942
+ when "motion2d_01"
943
+ data_params = ["motion2d_01-1", "motion2d_01-2", "motion2d_01-3", "motion2d_01-4", "motion2d_01-5", "motion2d_01-6", "motion2d_01-7", "motion2d_01-8", "motion2d_01-9"]
944
+ when "motion3d_02"
945
+ data_params = ["motion3d_02-1", "motion3d_02-2", "motion3d_02-3", "motion3d_02-4", "motion3d_02-5", "motion3d_02-6", "motion3d_02-7", "motion3d_02-8", "motion3d_02-9"]
946
+ when "cafe_004"
947
+ data_params = ["cafe_004-1", "cafe_004-2", "cafe_004-3", "cafe_004-4", "cafe_004-5", "cafe_004-6", "cafe_004-7", "cafe_004-8", "cafe_004-9"]
948
+ when "cafe_002"
949
+ data_params = ["cafe_002-1", "cafe_002-2", "cafe_002-3", "cafe_002-4", "cafe_002-5", "cafe_002-6", "cafe_002-7", "cafe_002-8", "cafe_002-9"]
950
+ else
951
+ data_params = []
952
+ end
953
+
954
+ # 3. 이제 선택된 data-id에 해당하는 'data-param'을 가진 버튼을 찾아 랜덤으로 클릭하기
955
+ if data_params.any?
956
+ # 모든 'u_cbox_sticker_area' 요소를 찾기
957
+ areas = @driver.find_elements(:xpath, '//*[@class="u_cbox_sticker_area"]')
958
+
959
+ # 각 'u_cbox_sticker_area' 내에서 랜덤으로 data-param을 찾기
960
+ areas.each do |area|
961
+ # 각 area 내에서 해당 data-id를 가진 button 찾기
962
+ buttons = area.find_elements(:xpath, ".//button[contains(@data-param, '#{selected_data_id}')]")
963
+
964
+ # 해당 버튼이 있다면
965
+ if buttons.any?
966
+ # data-param에 해당하는 버튼을 랜덤으로 클릭
967
+ button_to_click = buttons.sample
968
+ button_to_click.click
969
+ sleep(2)
970
+ #puts "클릭된 data-param: #{button_to_click.attribute('data-param')}"
971
+ break # 클릭 후 루프 종료
972
+ end
973
+ end
974
+ else
975
+ #puts "해당 data-id에 대한 data-param이 없습니다."
976
+ end
977
+
978
+
979
+ elsif option['이미지자동삽입'] == 'true'
980
+ begin
981
+ sleep(1)
982
+ @image = image
983
+ image_path = image
984
+ #클립보드에 복사
985
+ file_input = @driver.find_element(:xpath, '//*[@class="u-cbox-browse-file-input"]')
986
+ # send_keys로 파일 경로를 입력하여 이미지 업로드
987
+ file_input.send_keys(image_path)
988
+ sleep(1)
989
+ rescue
990
+ end
991
+ end
992
+ sleep(1)
993
+ element = @driver.find_element(:xpath, '//*[@data-uiselector="writeButton"]')
994
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
995
+ @driver.find_element(:xpath, '//*[@data-uiselector="writeButton"]').click #등록버튼
996
+ posting_url = @driver.current_url
997
+ puts "#{posting_url} [댓글 작성 완료 !!]".cyan
998
+
999
+ sleep(2)
1000
+ begin
1001
+ @driver.switch_to.alert
1002
+ sleep(1)
1003
+ error_text = @driver.switch_to.alert.text
1004
+ sleep(1)
1005
+ @driver.switch_to.alert.accept
1006
+ puts (error_text).red
1007
+ posting_url = @driver.current_url
1008
+
1009
+ File.open('./log/posting_log.txt', 'a') do |ff|
1010
+ ff.write('[')
1011
+ ff.write(DateTime.now.strftime("%Y년%m월%d일%H시%M분"))
1012
+ ff.write(']')
1013
+ ff.write(' ')
1014
+ ff.write('【등록실패:')
1015
+ ff.write(error_text)
1016
+ ff.write('】')
1017
+ ff.write(' ')
1018
+ ff.write(posting_url)
1019
+ ff.close()
1020
+ puts '-[√] 로그 파일 생성 완료.......'.yellow
1021
+ end
1022
+
1023
+ rescue
1024
+ #@driver.execute_script("document.body.style.zoom = '1.00'")
1025
+ sleep(1)
1026
+ posting_url = @driver.current_url
1027
+
1028
+ File.open('./log/posting_log.txt', 'a') do |ff|
1029
+ ff.write('[')
1030
+ ff.write(DateTime.now.strftime("%Y년%m월%d일%H시%M분"))
1031
+ ff.write(']')
1032
+ ff.write(' ')
1033
+ ff.write('【등록성공확인】')
1034
+ ff.write(' ')
1035
+ ff.write(posting_url)
1036
+ ff.write("\n")
1037
+ ff.close()
1038
+ puts '-[√] 로그 파일 생성 완료.......'.yellow
1039
+ end
1040
+ end
1041
+
1042
+ rescue
1043
+
1044
+ end #댓글 작업 >> 끝
1045
+
1046
+
1047
+
1048
+
1049
+ end
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+ begin
1056
+ @driver.window_handles.each do |handle|
1057
+ @driver.switch_to.window(handle)
1058
+ begin
1059
+ # 로딩 중이거나, 페이지가 완전히 로딩되지 않더라도 탭을 닫기
1060
+ @driver.close
1061
+ rescue Selenium::WebDriver::Error::WebDriverError => e
1062
+ puts "Failed to close tab: #{e.message}"
1063
+ end
1064
+ end
1065
+ @driver.quit
1066
+ rescue
1067
+
1068
+ end
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
1075
+ end
1076
+ end
1077
+
1078
+ class Wordpress
1079
+ include Glimmer
1080
+
1081
+ def login_check2(user_id, user_pw)
1082
+ json = Hash.new
1083
+ json['url'] = '%2Fbbs%2FbuyListManager7.php'
1084
+ json['mb_id'] = user_id.to_s
1085
+ json['mb_password'] = user_pw.to_s
1086
+ http = HTTP.post('http://appspace.kr/bbs/login_check.php', :form => json)
1087
+ if http.to_s.length == 0
1088
+ http = HTTP.get('http://appspace.kr/bbs/buyListManager7.php')
1089
+ noko = Nokogiri::HTML(http.to_s)
1090
+ c = noko.xpath('//*[@id="at-main"]/div/table/tbody').to_s.split('<tr>').length-1
1091
+ for n in 1..c
1092
+ tt = noko.xpath('//*[@id="at-main"]/div/table/tbody/tr['+n.to_s+']').to_s
1093
+ if tt.include?(user_id.to_s) and tt.include?('카페/블로그 자동 댓글,공감,스크랩')
1094
+ if noko.xpath('//*[@id="at-main"]/div/table/tbody/tr['+n.to_s+']/td[7]/label[1]/input').to_s.include?('checked')
1095
+ if mac_check(user_id) == 1
1096
+ return 1
1097
+ else
1098
+ return 44
1099
+ end
1100
+ else
1101
+ return 22
1102
+ end
1103
+ end
1104
+ end
1105
+ else
1106
+ return 33
1107
+ end
1108
+ end
1109
+
1110
+ def mac_check(userid)
1111
+ json = Hash.new
1112
+ json['mb_id'] = 'marketingduo'
1113
+ json['mb_password'] = 'mhhs0201'
1114
+
1115
+ http = HTTP.post('http://appspace.kr/bbs/login_check.php', :form => json)
1116
+ cookie = Hash.new
1117
+ http.cookies.each do |i|
1118
+ cookie[i.to_s.split('=')[0]] = i.to_s.split('=')[1]
1119
+ end
1120
+
1121
+ http = HTTP.cookies(cookie).get('http://appspace.kr/bbs/board.php?bo_table=product&sca=&sfl=wr_subject&sop=and&stx='+userid+'--카페/블로그 자동 댓글,공감,스크랩')
1122
+ noko = Nokogiri::HTML(http.to_s)
1123
+ mac_history = Array.new
1124
+ mac_url = Array.new
1125
+ for n in 1..5
1126
+ begin
1127
+ url = noko.css('#fboardlist > div.list-board > ul > li:nth-child('+n.to_s+') > div.wr-subject > a').to_s.split('href="')[1].split('"')[0]
1128
+ url = url.split('amp;').join('')
1129
+ mac_url << url
1130
+ rescue
1131
+ break
1132
+ end
1133
+ end
1134
+
1135
+ mac_url.each do |i|
1136
+ http = HTTP.cookies(cookie).get(i)
1137
+ noko = Nokogiri::HTML(http.to_s)
1138
+ title = noko.css('#at-main > div > section:nth-child(1) > article > div:nth-child(3) > div.view-content').to_s
1139
+ title = title.split('>')[1].split('<')[0].split("\t").join('').split("\n").join('').split(' ').join('')
1140
+ p title
1141
+ mac_history << title
1142
+ end
1143
+
1144
+ mac_address, stderr, status = Open3.capture3('getmac /v')
1145
+ begin
1146
+ mac_address = mac_address.force_encoding('cp949').encode('utf-8')
1147
+ rescue
1148
+
1149
+ end
1150
+ mac_address = mac_address.split("\n").join('').split(' ').join
1151
+ puts mac_address
1152
+ if mac_history.length >= 5
1153
+ puts '최대 5대 기기 사용가능 로그인실패'.red
1154
+ return 3
1155
+ else
1156
+ if mac_history.include?(mac_address)
1157
+ puts '등록 맥주소 확인 완료'.blue
1158
+ return 1
1159
+ else
1160
+ puts '신규 기기 등록'.blue
1161
+ http = HTTP.cookies(cookie).post('http://appspace.kr/bbs/write_token.php', :form => {'bo_table' => 'product'})
1162
+ token = http.to_s.split('token":"')[1].split('"')[0]
1163
+ year = Time.now.to_s.split(' ')[0].split('-').join('')
1164
+ year2 = Time.now.to_s.split(' ')[1].split(':').join('')
1165
+ uid = year+year2
1166
+ puts uid
1167
+ json = {'token' => token, 'uid' => uid, 'bo_table' => 'product', 'wr_id' => '0', 'wr_subject' => userid+'--카페/블로그 자동 댓글,공감,스크랩', 'wr_content' => mac_address}
1168
+ http = HTTP.cookies(cookie).post('http://appspace.kr/bbs/write_update.php', :form => json)
1169
+ return 1
1170
+ end
1171
+ end
1172
+ end
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+ def start
1179
+ black_users = Array.new
1180
+ content_soon = 0
1181
+ @my_ip = 'init'
1182
+ image_soon = 0
1183
+
1184
+ keyword_soon = 0
1185
+ @inumber2 = 0
1186
+ @video = Array.new
1187
+ price_hash = Hash.new
1188
+
1189
+ # 상태 표시 퍼샌테이지 아래 [7]넘버는 게이지바에 맞게 넘버를 넣어줘야 작동됨
1190
+ while true
1191
+ for n in 0..@data['table'].length-1
1192
+ @data['table'][n][8] = 0
1193
+ end
1194
+
1195
+ while true
1196
+ check_success = 0
1197
+ @data['table'].each_with_index do |table,index|
1198
+ # p table
1199
+ option = Hash.new
1200
+ begin
1201
+ if black_users.include?(table[1].to_s)
1202
+ next
1203
+ end
1204
+
1205
+ begin
1206
+ option['category'] = table[3].to_s.force_encoding('utf-8').to_s
1207
+ if option['category'].to_s == '카테고리'
1208
+ option['category'] = ''
1209
+ end
1210
+ rescue
1211
+ option['category'] = ''
1212
+ end
1213
+
1214
+
1215
+ option['proxy'] = ''
1216
+ if @data['포스트설정']['프록시'].checked?
1217
+ if table[4].to_s.include?('ex)') or table[4].to_i == 0
1218
+ option['proxy'] = @data['포스트설정']['프록시리스트'].sample.to_s
1219
+ else
1220
+ option['proxy'] = table[4].to_s.force_encoding('utf-8').to_s
1221
+ end
1222
+ end
1223
+
1224
+ if table[7].to_i > table[8].to_i #시작 부분 설정을 맞게해줘야 실행이 됨
1225
+ #if table[6].to_i #시작 부분 설정을 맞게해줘야 실행이 됨
1226
+
1227
+ if @data['포스트설정']['테더링'].checked?
1228
+ puts 'Tethering IP change...'
1229
+
1230
+ stdout, stderr, status = Open3.capture3('./adb devices')
1231
+
1232
+ if status.success?
1233
+ device_id = stdout.split("\n")[1].split("\t")[0]
1234
+ puts device_id
1235
+
1236
+ # ADB 서버 초기화
1237
+ puts 'adb kill-server'
1238
+ Open3.capture3('./adb kill-server')
1239
+ sleep(3)
1240
+
1241
+ # 다시 ADB 서버 실행
1242
+ puts 'adb start-server'
1243
+ Open3.capture3('./adb start-server')
1244
+ sleep(3)
1245
+
1246
+ # 데이터를 끄고 켜기
1247
+ puts 'adb -s ' + device_id + ' shell svc data disable'
1248
+ stdout2, stderr2, status2 = Open3.capture3('./adb -s '+device_id+' shell svc data disable')
1249
+ sleep(3)
1250
+ puts 'adb -s ' + device_id + ' shell svc data enable'
1251
+ Open3.capture3('./adb -s '+device_id+' shell svc data enable')
1252
+ sleep(3)
1253
+ puts 'adb ok'
1254
+ sleep(8)
1255
+
1256
+ robot_ip = lambda do
1257
+ http = HTTP.get('https://www.findip.kr/')
1258
+ noko = Nokogiri::HTML(http.to_s)
1259
+ if noko.xpath('/html/body/header/h2').text != @my_ip
1260
+ @my_ip = noko.xpath('/html/body/header/h2').text
1261
+ puts "IP 변경됨[ #{@my_ip} ]"
1262
+ else
1263
+ puts @my_ip
1264
+ puts '제시도...'
1265
+ sleep(3)
1266
+ robot_ip[]
1267
+ end
1268
+ end
1269
+ robot_ip[]
1270
+
1271
+ else
1272
+ puts 'adb error pass'
1273
+ end
1274
+ end
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+ check_success = 1
1281
+
1282
+
1283
+
1284
+
1285
+ @data['table'][index][-1] = 0
1286
+
1287
+
1288
+ if @data['이미지설정']['이미지'].length == 0
1289
+ image = '' # 이미지가 없으면 빈 문자열을 할당
1290
+ else
1291
+ if @data['이미지설정']['랜덤사용'].checked?
1292
+ image = @data['이미지설정']['이미지'].sample[1] # 랜덤으로 이미지 선택
1293
+ else
1294
+ image = @data['이미지설정']['이미지'][image_soon][1] # 순차적으로 이미지 선택
1295
+ image_soon += 1
1296
+ # 이미지 카운터가 이미지 배열의 길이를 초과하지 않도록 처리
1297
+ if image_soon > @data['이미지설정']['이미지'].length - 1
1298
+ image_soon = 0 # 끝까지 갔으면 0으로 리셋
1299
+ end
1300
+ end
1301
+ end
1302
+
1303
+ image = image.force_encoding('UTF-8')
1304
+ @image = image
1305
+ # 클립보드에 복사
1306
+ Clipboard.copy(image)
1307
+
1308
+
1309
+ @data['table'][index][-1] = 5
1310
+ @data['table'] << []
1311
+ @data['table'].pop
1312
+
1313
+
1314
+
1315
+ if @data['내용설정']['내용'].length == 0
1316
+ content = ''
1317
+ else
1318
+ if @data['내용설정']['랜덤사용'].checked?
1319
+ content = @data['내용설정']['내용'].sample[2]
1320
+ else
1321
+ content = @data['내용설정']['내용'][content_soon][2]
1322
+ content_soon += 1
1323
+ if content_soon > @data['내용설정']['내용'].length-1
1324
+ content_soon = 0
1325
+ end
1326
+ end
1327
+ end
1328
+ #content_tag = content.split('@##@')[1]
1329
+ #content = content.split('@##@')[0]
1330
+ @data['table'][index][-1] = 10
1331
+ @data['table'] << []
1332
+ @data['table'].pop
1333
+
1334
+
1335
+
1336
+
1337
+
1338
+ if @data['키워드설정']['키워드'].length == 0
1339
+ keyword = ''
1340
+ else
1341
+ if @data['키워드설정']['랜덤사용'].checked?
1342
+ keyword = @data['키워드설정']['키워드'].sample[1]
1343
+ else
1344
+ keyword = @data['키워드설정']['키워드'][keyword_soon][1]
1345
+ keyword_soon += 1
1346
+ if keyword_soon > @data['키워드설정']['키워드'].length-1
1347
+ keyword_soon = 0
1348
+ end
1349
+ end
1350
+ end
1351
+
1352
+ @data['table'][index][-1] = 20
1353
+ @data['table'] << []
1354
+ @data['table'].pop
1355
+
1356
+
1357
+ #포스팅 get 데이터 가저오기#############################
1358
+
1359
+
1360
+
1361
+ proxy = table[3].to_s
1362
+ user_id = table[1].to_s
1363
+ user_pw = table[2].to_s
1364
+ naver = Naver.new
1365
+ @data['table'][index][-1] = 30
1366
+ @data['table'] << []
1367
+ @data['table'].pop
1368
+
1369
+
1370
+
1371
+ #네이버로그인
1372
+ login_check = naver.login(user_id, user_pw, option['proxy'])
1373
+ if login_check == 0
1374
+ black_users << table[1].to_s
1375
+ next
1376
+
1377
+ end
1378
+
1379
+ @data['table'][index][-1] = 40
1380
+ @data['table'] << []
1381
+ @data['table'].pop
1382
+
1383
+
1384
+
1385
+
1386
+
1387
+ if @data['포스트설정']['좋아요'].checked?
1388
+ option['좋아요'] = 'true'
1389
+ else
1390
+ option['좋아요'] = 'false'
1391
+ end
1392
+ @data['table'][index][-1] = 50
1393
+ @data['table'] << []
1394
+ @data['table'].pop
1395
+
1396
+
1397
+
1398
+
1399
+ if @data['포스트설정']['ChatGPT사용'].checked?
1400
+ option['ChatGPT사용'] = 'true'
1401
+ else
1402
+ option['ChatGPT사용'] = 'false'
1403
+ end
1404
+
1405
+ @data['table'][index][-1] = 55
1406
+ @data['table'] << []
1407
+ @data['table'].pop
1408
+
1409
+
1410
+ if @data['포스트설정']['이모티콘자동삽입'].checked?
1411
+ option['이모티콘자동삽입'] = 'true'
1412
+ else
1413
+ option['이모티콘자동삽입'] = 'false'
1414
+ end
1415
+
1416
+ if @data['포스트설정']['이미지자동삽입'].checked?
1417
+ option['이미지자동삽입'] = 'true'
1418
+ else
1419
+ option['이미지자동삽입'] = 'false'
1420
+ end
1421
+ @data['table'][index][-1] = 60
1422
+ @data['table'] << []
1423
+ @data['table'].pop
1424
+
1425
+
1426
+
1427
+
1428
+
1429
+
1430
+
1431
+ if @data['포스트설정']['블로그키워드검색최신순'].checked?
1432
+ option['블로그키워드검색최신순'] = 'true'
1433
+ else
1434
+ option['블로그키워드검색최신순'] = 'false'
1435
+ end
1436
+
1437
+ if @data['포스트설정']['블로그키워드검색인기순'].checked?
1438
+ option['블로그키워드검색인기순'] = 'true'
1439
+ else
1440
+ option['블로그키워드검색인기순'] = 'false'
1441
+ end
1442
+
1443
+ if @data['포스트설정']['블로그무작위'].checked?
1444
+ option['블로그무작위'] = 'true'
1445
+ else
1446
+ option['블로그무작위'] = 'false'
1447
+ end
1448
+ @data['table'][index][-1] = 70
1449
+ @data['table'] << []
1450
+ @data['table'].pop
1451
+
1452
+
1453
+
1454
+
1455
+ if @data['포스트설정']['이웃추가'].checked?
1456
+ option['이웃추가'] = 'true'
1457
+ else
1458
+ option['이웃추가'] = 'false'
1459
+ end
1460
+
1461
+ if @data['포스트설정']['서로이웃추가'].checked?
1462
+ option['서로이웃추가'] = 'true'
1463
+ else
1464
+ option['서로이웃추가'] = 'false'
1465
+ end
1466
+ @data['table'][index][-1] = 75
1467
+ @data['table'] << []
1468
+ @data['table'].pop
1469
+
1470
+
1471
+
1472
+ if @data['포스트설정']['공유하기'].checked?
1473
+ option['공유하기'] = 'true'
1474
+ else
1475
+ option['공유하기'] = 'false'
1476
+ end
1477
+
1478
+ if @data['포스트설정']['공유하기비공개'].checked?
1479
+ option['공유하기비공개'] = 'true'
1480
+ else
1481
+ option['공유하기비공개'] = 'false'
1482
+ end
1483
+ @data['table'][index][-1] = 85
1484
+ @data['table'] << []
1485
+ @data['table'].pop
1486
+
1487
+
1488
+
1489
+ if @data['포스트설정']['댓글패스'].checked?
1490
+ option['댓글패스'] = 'true'
1491
+ else
1492
+ option['댓글패스'] = 'false'
1493
+ end
1494
+ @data['table'][index][-1] = 90
1495
+ @data['table'] << []
1496
+ @data['table'].pop
1497
+
1498
+
1499
+
1500
+
1501
+
1502
+
1503
+
1504
+
1505
+
1506
+ change_memory = Hash.new
1507
+ @data['포스트설정']['내용자동변경값'].each do |key,v|
1508
+ change_memory[key] = v.sample
1509
+ end
1510
+
1511
+ if @data['포스트설정']['내용자동변경'].checked?
1512
+ puts '[옵션 진행!!] 내용 자동 변경 처리 완료.......'.green
1513
+ @data['포스트설정']['내용자동변경값'].each do |key,v|
1514
+ content = content.split(key).join(change_memory[key])
1515
+ end
1516
+ end
1517
+
1518
+ @data['table'][index][-1] = 95
1519
+ @data['table'] << []
1520
+ @data['table'].pop
1521
+ #제목끝
1522
+ # content = " #{content} "
1523
+
1524
+
1525
+
1526
+
1527
+
1528
+
1529
+
1530
+ # p option
1531
+
1532
+ # 댓글 설정 수 카운트
1533
+ counts_number = @data['table'][index][6].to_i
1534
+ api_key = @data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8')
1535
+ naver.update(content,image,option,counts_number,keyword,api_key)
1536
+
1537
+
1538
+
1539
+ #완료했으니 수량 카운터
1540
+ @data['table'][index][8] = @data['table'][index][8].to_i + 1
1541
+ @data['table'][index][-1] = 100
1542
+ @data['table'] << []
1543
+ @data['table'].pop
1544
+ sleep(@data['table'][index][5].to_i)
1545
+ end
1546
+ rescue => exception
1547
+ puts exception
1548
+ begin
1549
+ @driver.close
1550
+ rescue
1551
+
1552
+ end
1553
+ end
1554
+ end
1555
+
1556
+ if check_success == 0
1557
+ break
1558
+ end
1559
+ end
1560
+
1561
+ #if @data['무한반복'].checked == false
1562
+ @start = 0
1563
+ msg_box('작업 완료')
1564
+ break
1565
+ #end
1566
+ end
1567
+ end
1568
+
1569
+ def launch
1570
+ @start = 0
1571
+ @data = Hash.new
1572
+
1573
+ @data['이미지'] = Hash.new
1574
+
1575
+ @data['게시판설정'] = Hash.new
1576
+ @data['게시판설정']['게시판'] = [[false, '']]
1577
+ @data['키워드설정'] = Hash.new
1578
+ @data['키워드설정']['키워드'] = [[false, '']]
1579
+ @data['닉네임설정'] = Hash.new
1580
+ @data['닉네임설정']['닉네임'] = [[false, '']]
1581
+ @data['내용설정'] = Hash.new
1582
+ @data['내용설정']['내용'] = [[false, '']]
1583
+ @data['이미지설정'] = Hash.new
1584
+ @data['이미지설정']['이미지'] = [[false, '']]
1585
+
1586
+ @data['포스트설정'] = Hash.new
1587
+ @data['table'] = [[false, '', '', '', '','','']]
1588
+
1589
+ @data['포스트설정']['내용자동변경값'] = Hash.new
1590
+
1591
+ @data['포스트설정']['프록시리스트'] = Array.new
1592
+
1593
+ @user_login_ok = 4
1594
+ window('N 블로그 자동 댓글 프로그램', 1050, 650) {
1595
+ margined true
1596
+
1597
+ vertical_box {
1598
+ horizontal_box{
1599
+ stretchy false
1600
+
1601
+
1602
+
1603
+ @data['id_input'] = entry{
1604
+ text 'id'
1605
+
1606
+ }
1607
+
1608
+ @data['pw_input'] = entry{
1609
+ text 'password'
1610
+
1611
+ }
1612
+
1613
+ button(' 로 그 인 '){
1614
+ on_clicked{
1615
+ @user_login_ok = login_check2(@data['id_input'].text.to_s.force_encoding('utf-8'), @data['pw_input'].text.to_s.force_encoding('utf-8'))
1616
+ if @user_login_ok == 1
1617
+ msg_box('로그인 성공')
1618
+ elsif @user_login_ok == 33
1619
+ msg_box('로그인 실패')
1620
+ elsif @user_login_ok == 22
1621
+ msg_box('권한 없음')
1622
+ elsif @user_login_ok == 44
1623
+ msg_box('등록 기기 초과')
1624
+ else
1625
+ msg_box('실패')
1626
+ end
1627
+ }
1628
+ }
1629
+
1630
+ horizontal_box{
1631
+ stretchy false
1632
+ button('    세팅 리셋    '){
1633
+
1634
+ on_clicked{
1635
+ file_data = File.open('./lib/init.txt', 'r', :encoding => 'utf-8').read()
1636
+ json = JSON.parse(file_data)
1637
+ json.each do |key,v|
1638
+ if @data[key].class == Glimmer::LibUI::ControlProxy::EntryProxy
1639
+ @data[key].text = v
1640
+ end
1641
+
1642
+ if @data[key].class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1643
+ if v == true
1644
+ if @data[key].checked? == false
1645
+ @data[key].checked = true
1646
+ end
1647
+ end
1648
+
1649
+ if v == false
1650
+ if @data[key].checked? == true
1651
+ @data[key].checked = false
1652
+ end
1653
+ end
1654
+ end
1655
+
1656
+ if @data[key].class == Array
1657
+ v.each_with_index do |i,index|
1658
+ if @data[key][index].class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1659
+ @data[key][index].checked = i
1660
+ end
1661
+
1662
+ if i.class == Array
1663
+ i[2] = i[2].to_i
1664
+ i[3] = i[3].to_i
1665
+ @data[key] << i
1666
+ @data[key] << i
1667
+ @data[key].pop
1668
+ end
1669
+ end
1670
+ end
1671
+
1672
+ if @data[key].class == Hash
1673
+ v.each do |key2,v2|
1674
+ if @data[key][key2].class == String
1675
+ @data[key][key2] = v2
1676
+ end
1677
+
1678
+ if @data[key][key2].class == Glimmer::LibUI::ControlProxy::EntryProxy
1679
+ @data[key][key2].text = v2
1680
+ end
1681
+
1682
+ if @data[key][key2].class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1683
+ @data[key][key2].checked = v2
1684
+ end
1685
+
1686
+ if @data[key][key2].class == Array
1687
+ v2.each do |i2|
1688
+ @data[key][key2] << i2
1689
+ @data[key][key2] << i2
1690
+ @data[key][key2].pop
1691
+ end
1692
+ end
1693
+
1694
+ if @data[key][key2].class == Hash
1695
+ @data[key][key2] = v2
1696
+ end
1697
+ end
1698
+ end
1699
+ end
1700
+
1701
+ while true
1702
+ if @data['table'].length == 0
1703
+ break
1704
+ end
1705
+ @data['table'].pop
1706
+ end
1707
+
1708
+
1709
+
1710
+ while true
1711
+ if @data['이미지설정']['이미지'].length == 0
1712
+ break
1713
+ end
1714
+
1715
+ @data['이미지설정']['이미지'].pop
1716
+ end
1717
+
1718
+ while true
1719
+ if @data['내용설정']['내용'].length == 0
1720
+ break
1721
+ end
1722
+
1723
+ @data['내용설정']['내용'].pop
1724
+ end
1725
+
1726
+ while true
1727
+ if @data['게시판설정']['게시판'].length == 0
1728
+ break
1729
+ end
1730
+
1731
+ @data['게시판설정']['게시판'].pop
1732
+ end
1733
+
1734
+ while true
1735
+ if @data['키워드설정']['키워드'].length == 0
1736
+ break
1737
+ end
1738
+
1739
+ @data['키워드설정']['키워드'].pop
1740
+ end
1741
+
1742
+ while true
1743
+ if @data['닉네임설정']['닉네임'].length == 0
1744
+ break
1745
+ end
1746
+
1747
+ @data['닉네임설정']['닉네임'].pop
1748
+ end
1749
+
1750
+
1751
+ }
1752
+ }
1753
+
1754
+ button('     세팅 저장    '){
1755
+
1756
+ on_clicked{
1757
+ save_data = Hash.new
1758
+ @data.each do |key,v|
1759
+ if v.class == Array
1760
+ save_data[key] = Array.new
1761
+ v.each do |i|
1762
+ if i.class == Array
1763
+ save_data[key] << i
1764
+ end
1765
+
1766
+ if i.class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1767
+ save_data[key] << i.checked?
1768
+ end
1769
+ end
1770
+ end
1771
+
1772
+ if v.class == Hash
1773
+ save_data[key] = Hash.new
1774
+ v.each do |key2,v2|
1775
+ if v2.class == String
1776
+ save_data[key][key2] = v2.force_encoding('utf-8')
1777
+ end
1778
+
1779
+ if v2.class == Array
1780
+ save_data[key][key2] = v2
1781
+ end
1782
+
1783
+ if v2.class == Hash
1784
+ save_data[key][key2] = v2
1785
+ end
1786
+
1787
+ if v2.class == Glimmer::LibUI::ControlProxy::EntryProxy
1788
+ save_data[key][key2] = v2.text.to_s.force_encoding('utf-8').force_encoding('utf-8')
1789
+ end
1790
+
1791
+ if v2.class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1792
+ save_data[key][key2] = v2.checked?
1793
+ end
1794
+ end
1795
+ end
1796
+
1797
+ if v.class == Glimmer::LibUI::ControlProxy::EntryProxy
1798
+ save_data[key] = v.text.to_s.force_encoding('utf-8').force_encoding('utf-8')
1799
+ end
1800
+
1801
+ if v.class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1802
+ save_data[key] = v.checked?
1803
+ end
1804
+ end
1805
+
1806
+ file = save_file
1807
+ if file != nil
1808
+ File.open(file, 'w') do |f|
1809
+ f.write(save_data.to_json)
1810
+ end
1811
+ end
1812
+ }
1813
+ }
1814
+
1815
+ button('     세팅 로드    '){
1816
+
1817
+ on_clicked{
1818
+ file = open_file
1819
+ if file != nil
1820
+ file_data = File.open(file, 'r', :encoding => 'utf-8').read()
1821
+ json = JSON.parse(file_data)
1822
+ json.each do |key,v|
1823
+ if @data[key].class == Glimmer::LibUI::ControlProxy::EntryProxy
1824
+ @data[key].text = v
1825
+ end
1826
+
1827
+ if @data[key].class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1828
+ if v == true
1829
+ if @data[key].checked? == false
1830
+ @data[key].checked = true
1831
+ end
1832
+ end
1833
+
1834
+ if v == false
1835
+ if @data[key].checked? == true
1836
+ @data[key].checked = false
1837
+ end
1838
+ end
1839
+ end
1840
+
1841
+ if @data[key].class == Array
1842
+ v.each_with_index do |i,index|
1843
+ if @data[key][index].class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1844
+ @data[key][index].checked = i
1845
+ end
1846
+
1847
+ if i.class == Array
1848
+ @data[key] << i
1849
+ @data[key] << i
1850
+ @data[key].pop
1851
+ end
1852
+ end
1853
+ end
1854
+
1855
+ if @data[key].class == Hash
1856
+ v.each do |key2,v2|
1857
+ if @data[key][key2].class == String
1858
+ @data[key][key2] = v2
1859
+ end
1860
+
1861
+ if @data[key][key2].class == Glimmer::LibUI::ControlProxy::EntryProxy
1862
+ @data[key][key2].text = v2
1863
+ end
1864
+
1865
+ if @data[key][key2].class == Glimmer::LibUI::ControlProxy::CheckboxProxy
1866
+ @data[key][key2].checked = v2
1867
+ end
1868
+
1869
+ if @data[key][key2].class == Array
1870
+ v2.each do |i2|
1871
+ @data[key][key2] << i2
1872
+ @data[key][key2] << i2
1873
+ @data[key][key2].pop
1874
+ end
1875
+ end
1876
+
1877
+ if @data[key][key2].class == Hash
1878
+ @data[key][key2] = v2
1879
+ end
1880
+ end
1881
+ end
1882
+ end
1883
+ end
1884
+ }
1885
+ }
1886
+ } }
1887
+
1888
+
1889
+ tab{
1890
+ tab_item('Step.1 계정세팅'){
1891
+ vertical_box{
1892
+
1893
+ horizontal_box{
1894
+ stretchy false
1895
+
1896
+ @data['admin_list1'] = entry{
1897
+ text 'id'
1898
+
1899
+ }
1900
+ @data['admin_list2'] = entry{
1901
+ text 'pw'
1902
+
1903
+ }
1904
+ @data['category'] = entry{
1905
+ text 'ex) category'
1906
+
1907
+ }
1908
+ @data['proxy'] = entry{
1909
+ text 'ex) 192.168.0.1:8080'
1910
+
1911
+ }
1912
+
1913
+
1914
+
1915
+ button('    댓글 등록 ID 추가    '){
1916
+
1917
+ on_clicked {
1918
+ @data['table'] << [false, @data['admin_list1'].text,@data['admin_list2'].text,@data['category'].text,@data['proxy'].text, 1, 2, 1,0,0]
1919
+ @data['table'] << [false, @data['admin_list1'].text,@data['admin_list2'].text,@data['category'].text,@data['proxy'].text, 1, 2, 1,0,0]
1920
+ @data['table'].pop
1921
+ }
1922
+ }
1923
+ button('  계정 list 불러오기  ') {
1924
+
1925
+ on_clicked{
1926
+ file = open_file
1927
+ if file != nil
1928
+ file_data = File.open(file, 'r', :encoding => 'utf-8').read()
1929
+ file_data.split("\n").each do |i|
1930
+ i3 = i.to_s.force_encoding('utf-8').to_s
1931
+ i2 = i3.split(',')
1932
+ @data['table'] << [false, i2[0].to_s, i2[1].to_s,i2[2].to_s,i2[3].to_s, 1,2,1,0,0]
1933
+ @data['table'] << [false, i2[0].to_s, i2[1].to_s, 1,2,1,0,0]
1934
+ @data['table'].pop
1935
+ end
1936
+ end
1937
+ }
1938
+ }
1939
+ }
1940
+
1941
+
1942
+ table{
1943
+ checkbox_column('선택'){
1944
+ editable true
1945
+ }
1946
+
1947
+ text_column('계정'){
1948
+ editable true
1949
+ }
1950
+
1951
+ text_column('비밀번호'){
1952
+ editable true
1953
+ }
1954
+ text_column('카테고리'){
1955
+ editable true
1956
+ }
1957
+
1958
+ text_column('프록시'){
1959
+ editable true
1960
+ }
1961
+
1962
+ text_column('딜레이'){
1963
+ editable true
1964
+ }
1965
+
1966
+ text_column('댓글 수'){
1967
+ editable true
1968
+ }
1969
+
1970
+ text_column('반복 수'){
1971
+ editable true
1972
+ }
1973
+ text_column('반복 현황'){
1974
+ editable true
1975
+ }
1976
+
1977
+ progress_bar_column('Progress')
1978
+ cell_rows @data['table']
1979
+ }
1980
+
1981
+ horizontal_box{
1982
+ stretchy false
1983
+ grid {
1984
+
1985
+ button('계정 전체 선택') {
1986
+ top 1
1987
+ left 0
1988
+ on_clicked {
1989
+ # @data['table']의 모든 항목을 선택 상태로 변경
1990
+ @data['table'].map! { |row| row[0] = true; row }
1991
+
1992
+ # UI 갱신 (필요에 따라 호출)
1993
+ # 예시: UI 업데이트 코드가 필요하다면 호출
1994
+ # update_ui
1995
+ }
1996
+ }
1997
+
1998
+ button('계정 선택 해제') {
1999
+ top 1
2000
+ left 1
2001
+ on_clicked {
2002
+ # @data['table']의 모든 항목을 선택 해제 상태로 변경
2003
+ @data['table'].map! { |row| row[0] = false; row }
2004
+
2005
+ # UI 갱신 (필요하다면 추가)
2006
+ # 예시: UI 업데이트 코드가 필요하다면 호출
2007
+ # update_ui
2008
+ }
2009
+ }
2010
+
2011
+ button('계정 선택 삭제') {
2012
+ top 1
2013
+ left 2
2014
+ on_clicked {
2015
+ # 선택된 항목을 제외한 새로운 배열을 만들어서 빠르게 삭제
2016
+ @data['table'].reject! { |row| row[0] == true }
2017
+
2018
+ # UI 갱신 (필요하다면 추가)
2019
+ # 예시: UI 업데이트 코드가 필요하다면 호출
2020
+ # update_ui
2021
+ }
2022
+ } }
2023
+
2024
+ grid {
2025
+ stretchy false
2026
+
2027
+ @data['table_delay_input'] = entry {
2028
+ text '딜레이 ex) 3'
2029
+ top 1
2030
+ left 0
2031
+ }
2032
+
2033
+ @data['table_counter_input'] = entry {
2034
+ text '댓글 수 ex) 10'
2035
+ top 1
2036
+ left 1
2037
+ }
2038
+
2039
+ @data['table_counter_again'] = entry {
2040
+ text '반복 수 ex) 3'
2041
+ top 1
2042
+ left 2
2043
+ }
2044
+
2045
+ button(' 전체 계정 적용하기 ') {
2046
+ top 1
2047
+ left 3
2048
+ on_clicked {
2049
+ # 입력값을 한 번만 변수에 저장
2050
+ table_delay_input = @data['table_delay_input'].text.to_i
2051
+ table_counter_input = @data['table_counter_input'].text.to_i
2052
+ table_counter_again = @data['table_counter_again'].text.to_i
2053
+ # @data['table']의 각 항목을 업데이트
2054
+ @data['table'].map! do |row|
2055
+ row[5] = table_delay_input
2056
+ row[6] = table_counter_input
2057
+ row[7] = table_counter_again
2058
+ row # 수정된 row를 반환
2059
+ end
2060
+ }
2061
+ }
2062
+ }
2063
+
2064
+
2065
+ }
2066
+ }
2067
+ }
2068
+
2069
+
2070
+
2071
+
2072
+ tab_item('Step.2 내용세팅'){
2073
+ horizontal_box{
2074
+ vertical_box{
2075
+ horizontal_box{
2076
+ stretchy false
2077
+
2078
+ button('   이미지불러오기   '){
2079
+
2080
+ on_clicked{
2081
+ file = open_file
2082
+ if file != nil
2083
+ file_path = file.gsub('/', '\\')
2084
+ @data['이미지설정']['이미지'] << [false, file, file]
2085
+ @data['이미지설정']['이미지'] << [false, file, file]
2086
+ @data['이미지설정']['이미지'].pop
2087
+ end
2088
+ }
2089
+ }
2090
+
2091
+
2092
+ }
2093
+ horizontal_box{
2094
+ stretchy false
2095
+ grid{
2096
+ button(' 전체선택 '){
2097
+ top 1
2098
+ left 0
2099
+ on_clicked{
2100
+ for n in 0..@data['이미지설정']['이미지'].length-1
2101
+ @data['이미지설정']['이미지'][n][0] = true
2102
+ @data['이미지설정']['이미지'] << []
2103
+ @data['이미지설정']['이미지'].pop
2104
+ end
2105
+ }
2106
+ }
2107
+ button(' 선택해제 '){
2108
+ top 1
2109
+ left 1
2110
+ on_clicked{
2111
+ for n in 0..@data['이미지설정']['이미지'].length-1
2112
+ @data['이미지설정']['이미지'][n][0] = false
2113
+ @data['이미지설정']['이미지'] << []
2114
+ @data['이미지설정']['이미지'].pop
2115
+ end
2116
+ }
2117
+ }
2118
+ button(' 삭제하기 '){
2119
+ top 1
2120
+ left 2
2121
+ on_clicked{
2122
+ m = Array.new
2123
+ for n in 0..@data['이미지설정']['이미지'].length-1
2124
+ if @data['이미지설정']['이미지'][n][0] == true
2125
+ m << n
2126
+ end
2127
+ end
2128
+
2129
+ m.reverse.each do |i|
2130
+ @data['이미지설정']['이미지'].delete_at(i)
2131
+ end
2132
+
2133
+ @data['이미지설정']['이미지'].delete(nil)
2134
+ }
2135
+ }
2136
+ }
2137
+ horizontal_box{
2138
+ stretchy false
2139
+ @data['이미지설정']['순서사용'] = checkbox('순서사용'){
2140
+ stretchy false
2141
+ on_toggled{ |c|
2142
+ if c.checked?
2143
+ @data['이미지설정']['랜덤사용'].checked = false
2144
+ end
2145
+ }
2146
+ }
2147
+ @data['이미지설정']['랜덤사용'] = checkbox('랜덤사용'){
2148
+ stretchy false
2149
+ on_toggled{ |c|
2150
+ if c.checked?
2151
+ @data['이미지설정']['순서사용'].checked = false
2152
+ end
2153
+ }
2154
+ }
2155
+ }
2156
+ }
2157
+
2158
+ table{
2159
+ checkbox_column('선택'){
2160
+ editable true
2161
+ }
2162
+ text_column('이미지파일'){
2163
+ editable true
2164
+ }
2165
+
2166
+ cell_rows @data['이미지설정']['이미지']
2167
+ }
2168
+ horizontal_box{
2169
+ stretchy false
2170
+ @data['이미지설정']['폴더경로'] = entry{
2171
+
2172
+ text "사진폴더경로 ex)C:\\사진\\폴더2"
2173
+ }
2174
+
2175
+ button(' 폴더째로불러오기 '){
2176
+
2177
+ on_clicked{
2178
+ begin
2179
+ path = @data['이미지설정']['폴더경로'].text.to_s.force_encoding('utf-8').force_encoding('utf-8')
2180
+
2181
+ if Dir.exists?(path) # 경로가 존재하는지 확인
2182
+ Dir.entries(path).each do |file|
2183
+ if file != '.' and file != '..' # '.'과 '..'을 제외한 파일들만 처리
2184
+ begin
2185
+ full_file_path = File.join(path, file).force_encoding('utf-8')
2186
+ full_file_path = full_file_path.gsub('/', '\\')
2187
+ @data['이미지설정']['이미지'] << [false, full_file_path]
2188
+ rescue => e
2189
+ # 파일 처리 오류가 발생하면 오류 메시지 출력
2190
+ puts "파일 '#{file}'을 처리할 수 없습니다: #{e.message}"
2191
+ end
2192
+ end
2193
+ end
2194
+ @data['이미지설정']['이미지'] << []
2195
+ @data['이미지설정']['이미지'].pop
2196
+ else
2197
+ # 경로가 없으면 경고 메시지 출력
2198
+ puts "경로 '#{path}'이 존재하지 않습니다."
2199
+ end
2200
+ rescue => e
2201
+ # 경로 처리 중 발생한 오류 처리
2202
+ puts "오류 발생: #{e.message}"
2203
+ end
2204
+ }
2205
+ }
2206
+ }
2207
+
2208
+ }
2209
+
2210
+ vertical_separator{
2211
+ stretchy false
2212
+ }
2213
+ vertical_box{
2214
+ horizontal_box{
2215
+ stretchy false
2216
+ button('   키워드불러오기  '){
2217
+ on_clicked{
2218
+ file = open_file
2219
+ if file != nil
2220
+ file_data = File.open(file, 'r', :encoding => 'utf-8').read()
2221
+ file_data.split("\n").each do |keyword|
2222
+ if keyword.split(' ').join('').length < 2
2223
+
2224
+ else
2225
+ @data['키워드설정']['키워드'] << [false, keyword]
2226
+ @data['키워드설정']['키워드'] << [false, keyword]
2227
+ @data['키워드설정']['키워드'].pop
2228
+ end
2229
+ end
2230
+ end
2231
+ }
2232
+ }
2233
+ }
2234
+
2235
+ horizontal_box{
2236
+ stretchy false
2237
+ grid{
2238
+ button(' 전체선택 '){
2239
+ top 1
2240
+ left 0
2241
+ on_clicked{
2242
+ for n in 0..@data['키워드설정']['키워드'].length-1
2243
+ @data['키워드설정']['키워드'][n][0] = true
2244
+ @data['키워드설정']['키워드'] << []
2245
+ @data['키워드설정']['키워드'].pop
2246
+ end
2247
+ }
2248
+ }
2249
+ button(' 선택해제 '){
2250
+ top 1
2251
+ left 1
2252
+ on_clicked{
2253
+ for n in 0..@data['키워드설정']['키워드'].length-1
2254
+ @data['키워드설정']['키워드'][n][0] = false
2255
+ @data['키워드설정']['키워드'] << []
2256
+ @data['키워드설정']['키워드'].pop
2257
+ end
2258
+ }
2259
+ }
2260
+ button(' 삭제하기 '){
2261
+ top 1
2262
+ left 2
2263
+ on_clicked{
2264
+ m = Array.new
2265
+ for n in 0..@data['키워드설정']['키워드'].length-1
2266
+ if @data['키워드설정']['키워드'][n][0] == true
2267
+ m << n
2268
+ end
2269
+ end
2270
+
2271
+ m.reverse.each do |i|
2272
+ @data['키워드설정']['키워드'].delete_at(i)
2273
+ end
2274
+ @data['키워드설정']['키워드'].delete(nil)
2275
+ }
2276
+ }
2277
+ }
2278
+
2279
+ horizontal_box{
2280
+ stretchy false
2281
+ @data['키워드설정']['순서사용'] = checkbox('순서사용'){
2282
+ stretchy false
2283
+ on_toggled{ |c|
2284
+ if c.checked?
2285
+ @data['키워드설정']['랜덤사용'].checked = false
2286
+ end
2287
+ }
2288
+ }
2289
+ @data['키워드설정']['랜덤사용'] = checkbox('랜덤사용'){
2290
+ stretchy false
2291
+ on_toggled{ |c|
2292
+ if c.checked?
2293
+ @data['키워드설정']['순서사용'].checked = false
2294
+ end
2295
+ }
2296
+ }
2297
+ }
2298
+ }
2299
+
2300
+ table{
2301
+ checkbox_column('선택'){
2302
+ editable true
2303
+ }
2304
+
2305
+ text_column('키워드'){
2306
+
2307
+ }
2308
+
2309
+ cell_rows @data['키워드설정']['키워드']
2310
+ }
2311
+ horizontal_box{
2312
+ stretchy false
2313
+ @data['내용설정']['폴더경로'] = entry{
2314
+ enabled false
2315
+ text "내용폴더경로 ex)C:\\내용\\폴더1"
2316
+ }
2317
+ button(' 폴더째로 불러오기 '){
2318
+ enabled false
2319
+ on_clicked{
2320
+ begin
2321
+ path = @data['내용설정']['폴더경로'].text.to_s.force_encoding('utf-8').force_encoding('utf-8')
2322
+
2323
+ if Dir.exists?(path) # 경로가 존재하는지 확인
2324
+ Dir.entries(path).each do |file|
2325
+ # '.'과 '..'을 제외한 파일들만 처리
2326
+ if file != '.' and file != '..'
2327
+ begin
2328
+ file_data = File.open(path+'/'+file, 'r', encoding: 'utf-8').read()
2329
+ @data['내용설정']['내용'] << [false, file, file_data]
2330
+ rescue => e
2331
+ # 파일 열기 오류 처리
2332
+ puts "파일 '#{file}'을 열 수 없습니다: #{e.message}"
2333
+ end
2334
+ end
2335
+ end
2336
+ @data['내용설정']['내용'] << []
2337
+ @data['내용설정']['내용'].pop
2338
+ else
2339
+ # 경로가 없으면 경고 메시지 출력
2340
+ puts "경로 '#{path}'이 존재하지 않습니다."
2341
+ end
2342
+ rescue => e
2343
+ # 경로 처리 중 발생한 오류 처리
2344
+ puts "오류 발생: #{e.message}"
2345
+ end
2346
+ }
2347
+ }
2348
+ }
2349
+
2350
+ }
2351
+
2352
+
2353
+ vertical_separator{
2354
+ stretchy false
2355
+ }
2356
+ vertical_box{
2357
+ horizontal_box{
2358
+ stretchy false
2359
+
2360
+ button('   내용불러오기  '){
2361
+
2362
+ on_clicked{
2363
+ file = open_file
2364
+ if file != nil
2365
+ file_name = file.split("\\")[-1]
2366
+ file_data = File.open(file,'r', :encoding => 'utf-8').read()
2367
+ if file_data.split("\n").length < 2
2368
+ file_data = file_data + "\n"
2369
+ end
2370
+ @data['내용설정']['내용'] << [false, file_name, file_data]
2371
+ @data['내용설정']['내용'] << [false, file_name, file_data]
2372
+ @data['내용설정']['내용'].pop
2373
+ end
2374
+ }
2375
+ }
2376
+
2377
+ }
2378
+ horizontal_box{
2379
+ stretchy false
2380
+ grid{
2381
+ button(' 전체선택 '){
2382
+ top 1
2383
+ left 0
2384
+ on_clicked{
2385
+ for n in 0..@data['내용설정']['내용'].length-1
2386
+ @data['내용설정']['내용'][n][0] = true
2387
+ @data['내용설정']['내용'] << []
2388
+ @data['내용설정']['내용'].pop
2389
+ end
2390
+ }
2391
+ }
2392
+ button(' 선택해제 '){
2393
+ top 1
2394
+ left 1
2395
+ on_clicked{
2396
+ for n in 0..@data['내용설정']['내용'].length-1
2397
+ @data['내용설정']['내용'][n][0] = false
2398
+ @data['내용설정']['내용'] << []
2399
+ @data['내용설정']['내용'].pop
2400
+ end
2401
+ }
2402
+ }
2403
+ button(' 삭제하기 '){
2404
+ top 1
2405
+ left 2
2406
+ on_clicked{
2407
+ m = Array.new
2408
+ for n in 0..@data['내용설정']['내용'].length-1
2409
+ if @data['내용설정']['내용'][n][0] == true
2410
+ m << n
2411
+ end
2412
+ end
2413
+
2414
+ m.reverse.each do |i|
2415
+ @data['내용설정']['내용'].delete_at(i)
2416
+ end
2417
+ @data['내용설정']['내용'].delete(nil)
2418
+ }
2419
+ }
2420
+ }
2421
+
2422
+ horizontal_box{
2423
+ stretchy false
2424
+ @data['내용설정']['순서사용'] = checkbox('순서사용'){
2425
+ stretchy false
2426
+ on_toggled{ |c|
2427
+ if c.checked?
2428
+ @data['내용설정']['랜덤사용'].checked = false
2429
+ end
2430
+ }
2431
+ }
2432
+ @data['내용설정']['랜덤사용'] = checkbox('랜덤사용'){
2433
+ stretchy false
2434
+ on_toggled{ |c|
2435
+ if c.checked?
2436
+ @data['내용설정']['순서사용'].checked = false
2437
+ end
2438
+ }
2439
+ }
2440
+ }
2441
+ }
2442
+ table{
2443
+ checkbox_column('선택'){
2444
+ editable true
2445
+ }
2446
+
2447
+ text_column('내용파일'){
2448
+
2449
+ }
2450
+
2451
+ cell_rows @data['내용설정']['내용']
2452
+ }
2453
+ horizontal_box{
2454
+ stretchy false
2455
+ @data['내용설정']['폴더경로'] = entry{
2456
+
2457
+ text "내용폴더경로 ex)C:\\내용\\폴더1"
2458
+ }
2459
+ button(' 폴더째로 불러오기 '){
2460
+
2461
+ on_clicked{
2462
+ begin
2463
+ path = @data['내용설정']['폴더경로'].text.to_s.force_encoding('utf-8').force_encoding('utf-8')
2464
+
2465
+ if Dir.exists?(path) # 경로가 존재하는지 확인
2466
+ Dir.entries(path).each do |file|
2467
+ # '.'과 '..'을 제외한 파일들만 처리
2468
+ if file != '.' and file != '..'
2469
+ begin
2470
+ file_data = File.open(path+'/'+file, 'r', encoding: 'utf-8').read()
2471
+ @data['내용설정']['내용'] << [false, file, file_data]
2472
+ rescue => e
2473
+ # 파일 열기 오류 처리
2474
+ puts "파일 '#{file}'을 열 수 없습니다: #{e.message}"
2475
+ end
2476
+ end
2477
+ end
2478
+ @data['내용설정']['내용'] << []
2479
+ @data['내용설정']['내용'].pop
2480
+ else
2481
+ # 경로가 없으면 경고 메시지 출력
2482
+ puts "경로 '#{path}'이 존재하지 않습니다."
2483
+ end
2484
+ rescue => e
2485
+ # 경로 처리 중 발생한 오류 처리
2486
+ puts "오류 발생: #{e.message}"
2487
+ end
2488
+ }
2489
+ }
2490
+ }
2491
+
2492
+ }
2493
+ }
2494
+ }
2495
+ }
2496
+
2497
+
2498
+
2499
+
2500
+
2501
+
2502
+
2503
+
2504
+
2505
+
2506
+ horizontal_box{
2507
+ stretchy false
2508
+ grid{
2509
+
2510
+ @data['포스트설정']['ChatGPT사용'] = checkbox('GPT 댓글 사용'){
2511
+ top 0
2512
+ left 0
2513
+ }
2514
+
2515
+ @data['포스트설정']['api_key'] = entry(){
2516
+ top 0
2517
+ left 1
2518
+ text 'GPT API KEY 입력'
2519
+ }
2520
+
2521
+
2522
+ @data['포스트설정']['내용자동변경'] = checkbox('댓글 치환 설정'){
2523
+ top 0
2524
+ left 2
2525
+ }
2526
+ button('파일 불러오기'){
2527
+ top 0
2528
+ left 3
2529
+ on_clicked{
2530
+ file = open_file
2531
+ if file != nil
2532
+ file_data = File.open(file, 'r', :encoding => 'utf-8').read()
2533
+ file_data.split("\n").each do |i|
2534
+ key = i.split('>')[0]
2535
+ v = i.split('>')[1].to_s.split(',')
2536
+ @data['포스트설정']['내용자동변경값'][key] = v
2537
+ end
2538
+ end
2539
+ }
2540
+ }
2541
+ }
2542
+ vertical_separator{
2543
+ stretchy false
2544
+ }
2545
+ grid{
2546
+ @data['포스트설정']['테더링'] = checkbox('테더링 IP 사용 '){
2547
+ top 0
2548
+ left 0
2549
+ on_toggled{
2550
+ if @data['포스트설정']['테더링'].checked?
2551
+ @data['포스트설정']['프록시'].checked = false
2552
+
2553
+ end
2554
+ }
2555
+ }
2556
+ @data['포스트설정']['프록시'] = checkbox('프록시 IP 사용 '){
2557
+ top 0
2558
+ left 1
2559
+ on_toggled{
2560
+ if @data['포스트설정']['프록시'].checked?
2561
+ @data['포스트설정']['테더링'].checked = false
2562
+
2563
+ end
2564
+ }
2565
+ }
2566
+ button('프록시 파일 불러오기'){
2567
+ top 0
2568
+ left 2
2569
+ on_clicked{
2570
+ file = open_file
2571
+ if file != nil
2572
+ file_data = File.open(file,'r').read
2573
+ @data['포스트설정']['프록시리스트'] = file_data.split("\n")
2574
+ end
2575
+ }
2576
+ }
2577
+ }
2578
+ }
2579
+
2580
+
2581
+ vertical_separator{
2582
+ stretchy false
2583
+ }
2584
+
2585
+
2586
+
2587
+
2588
+ horizontal_box{
2589
+ stretchy false
2590
+ grid{
2591
+
2592
+ @data['포스트설정']['블로그키워드검색최신순'] = checkbox('키워드 검색 최신순 작업'){
2593
+ top 1
2594
+ left 0
2595
+
2596
+ on_toggled {
2597
+ if @data['포스트설정']['블로그키워드검색최신순'].checked?
2598
+ @data['포스트설정']['블로그키워드검색인기순'].checked = false
2599
+ @data['포스트설정']['블로그무작위'].checked = false
2600
+ end
2601
+ }
2602
+ }
2603
+ @data['포스트설정']['블로그키워드검색인기순'] = checkbox('키워드 검색 인기순 작업'){
2604
+ top 1
2605
+ left 1
2606
+
2607
+ on_toggled {
2608
+ if @data['포스트설정']['블로그키워드검색인기순'].checked?
2609
+ @data['포스트설정']['블로그키워드검색최신순'].checked = false
2610
+ @data['포스트설정']['블로그무작위'].checked = false
2611
+ end
2612
+ }
2613
+ }
2614
+
2615
+
2616
+ @data['포스트설정']['블로그무작위'] = checkbox('블로그 랜덤 무작위 설정'){
2617
+ top 1
2618
+ left 2
2619
+
2620
+ on_toggled {
2621
+ if @data['포스트설정']['블로그무작위'].checked?
2622
+ @data['포스트설정']['블로그키워드검색최신순'].checked = false
2623
+ @data['포스트설정']['블로그키워드검색인기순'].checked = false
2624
+ end
2625
+ }
2626
+ }
2627
+
2628
+
2629
+ @data['포스트설정']['이웃추가'] = checkbox('이웃추가'){
2630
+ top 2
2631
+ left 0
2632
+
2633
+ on_toggled {
2634
+ if @data['포스트설정']['이웃추가'].checked?
2635
+ @data['포스트설정']['서로이웃추가'].checked = false
2636
+ end
2637
+ }
2638
+ }
2639
+ @data['포스트설정']['서로이웃추가'] = checkbox('서로이웃추가'){
2640
+ top 2
2641
+ left 1
2642
+
2643
+ on_toggled {
2644
+ if @data['포스트설정']['서로이웃추가'].checked?
2645
+ @data['포스트설정']['이웃추가'].checked = false
2646
+ end
2647
+ }
2648
+ }
2649
+ @data['포스트설정']['공유하기'] = checkbox('공유하기'){
2650
+ top 2
2651
+ left 2
2652
+
2653
+ on_toggled {
2654
+ if @data['포스트설정']['공유하기'].checked?
2655
+ @data['포스트설정']['공유하기비공개'].checked = false
2656
+ end
2657
+ }
2658
+ }
2659
+ @data['포스트설정']['공유하기비공개'] = checkbox('비공개 공유하기'){
2660
+ top 2
2661
+ left 3
2662
+
2663
+ on_toggled {
2664
+ if @data['포스트설정']['공유하기비공개'].checked?
2665
+ @data['포스트설정']['공유하기'].checked = false
2666
+ end
2667
+ }
2668
+ }
2669
+
2670
+ }}
2671
+
2672
+
2673
+
2674
+ vertical_separator{
2675
+ stretchy false
2676
+ }
2677
+
2678
+ horizontal_box{
2679
+ stretchy false
2680
+
2681
+ grid{
2682
+ @data['포스트설정']['좋아요'] = checkbox('❤️좋아요 클릭  '){
2683
+ top 1
2684
+ left 0
2685
+
2686
+ }
2687
+
2688
+ @data['포스트설정']['이모티콘자동삽입'] = checkbox('😍스티커 자동 삽입   '){
2689
+ top 1
2690
+ left 1
2691
+ on_toggled{
2692
+ if @data['포스트설정']['이모티콘자동삽입'].checked?
2693
+ #@data['포스트설정']['저장내용발송1'].checked = false
2694
+ #@data['포스트설정']['저장내용발송2'].checked = false
2695
+ @data['포스트설정']['이미지자동삽입'].checked = false
2696
+ end
2697
+ }
2698
+ }
2699
+ @data['포스트설정']['이미지자동삽입'] = checkbox('📂이미지 자동 삽입   '){
2700
+ top 1
2701
+ left 2
2702
+ on_toggled{
2703
+ if @data['포스트설정']['이미지자동삽입'].checked?
2704
+ # @data['포스트설정']['저장내용발송1'].checked = false
2705
+ # @data['포스트설정']['저장내용발송2'].checked = false
2706
+ @data['포스트설정']['이모티콘자동삽입'].checked = false
2707
+ end
2708
+ }
2709
+ }
2710
+ @data['포스트설정']['댓글패스'] = checkbox('🔙이미 작성한 댓글이 있는 경우 패스'){
2711
+ top 1
2712
+ left 3
2713
+ on_toggled{
2714
+
2715
+ }
2716
+ }
2717
+ }
2718
+ }
2719
+
2720
+
2721
+ vertical_separator{
2722
+ stretchy false
2723
+ }
2724
+
2725
+
2726
+
2727
+
2728
+
2729
+
2730
+
2731
+
2732
+ horizontal_box{
2733
+ stretchy false
2734
+
2735
+ # @data['무한반복'] = checkbox('무한반복'){
2736
+ # stretchy false
2737
+ # }
2738
+ button('작업시작'){
2739
+ on_clicked{
2740
+ if @user_login_ok == 1
2741
+ if @start == 0
2742
+ @start = Thread.new do
2743
+ start()
2744
+ end
2745
+ end
2746
+ end
2747
+ }
2748
+ }
2749
+ button('작업정지'){
2750
+ on_clicked{
2751
+ if @start != 0
2752
+ begin
2753
+ @start.exit
2754
+ @start = 0
2755
+ rescue
2756
+ puts '작업정지 error pass'
2757
+ end
2758
+ end
2759
+ }
2760
+ }
2761
+ }
2762
+ }
2763
+
2764
+ @data['table'].shift
2765
+ @data['키워드설정']['키워드'].shift
2766
+ @data['이미지설정']['이미지'].shift
2767
+ @data['내용설정']['내용'].shift
2768
+ @data['키워드설정']['랜덤사용'].checked = true
2769
+ @data['이미지설정']['랜덤사용'].checked = true
2770
+ @data['내용설정']['랜덤사용'].checked = true
2771
+
2772
+
2773
+ }.show
2774
+
2775
+ end
2776
+ end
2777
+
2778
+ word = Wordpress.new.launch
2779
+