nblog_duo 0.0.93 → 0.0.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nblog_duo.rb +33 -262
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0d546bfb6673bf0a285b06e5dd1faa7f52f6201e901885a87f4f5c594dd4bc6
|
4
|
+
data.tar.gz: 2af111f38eaeb1b324fedf176d5d1777d7732d92cb21810986d326c512bd2aa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abfc6ce9c19967af4e64251a4899510365d1531cc505a4b4ab9f6741f641fb44687e2f6e83093fe6abdd35e15fb679f79bf00258b7e44db454e1b6eab4df4ae3
|
7
|
+
data.tar.gz: 0af9f317a6d24287514bf1ee84a40eb34cfd08aa9ed8a4dd5d5018504e1a507e91253056ad32f896e4b0426a621661d87ec4951be24da34b4a422a84b6989128
|
data/lib/nblog_duo.rb
CHANGED
@@ -108,246 +108,6 @@ end
|
|
108
108
|
|
109
109
|
|
110
110
|
|
111
|
-
class Chat_title
|
112
|
-
def initialize(api_key, gpt_title_prompt)
|
113
|
-
@api_key = api_key
|
114
|
-
@gpt_title_prompt = gpt_title_prompt
|
115
|
-
end
|
116
|
-
|
117
|
-
def message(title)
|
118
|
-
puts 'Sending request to GPT...(제목 생성 중...)'
|
119
|
-
# "키워드 기반 글 생성 중..." 메시지를 별도 스레드로 처리
|
120
|
-
thread = Thread.new do
|
121
|
-
while true
|
122
|
-
print "▶"
|
123
|
-
sleep(3)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
url = 'https://api.openai.com/v1/chat/completions'
|
127
|
-
headers = {
|
128
|
-
'Content-Type' => 'application/json',
|
129
|
-
'Authorization' => 'Bearer ' + @api_key
|
130
|
-
}
|
131
|
-
data = {
|
132
|
-
'model' => 'gpt-4',
|
133
|
-
'messages' => [{
|
134
|
-
"role" => "system",
|
135
|
-
"content" => "너는 매우 친절하고 성의 있게 답변하는 AI 어시스턴트야."
|
136
|
-
},
|
137
|
-
{
|
138
|
-
"role" => "user",
|
139
|
-
"content" => "#{@gpt_title_prompt}\n#{title}"
|
140
|
-
}]
|
141
|
-
}
|
142
|
-
|
143
|
-
begin
|
144
|
-
req = HTTP.headers(headers).post(url, json: data)
|
145
|
-
|
146
|
-
response = JSON.parse(req.body.to_s)
|
147
|
-
|
148
|
-
|
149
|
-
if req.status == 429
|
150
|
-
return "API 요청 제한을 초과했습니다. 플랜 및 할당량을 확인하세요."
|
151
|
-
end
|
152
|
-
|
153
|
-
# 응답 데이터에서 안전하게 값 추출
|
154
|
-
answer = response.dig('choices', 0, 'message', 'content')
|
155
|
-
|
156
|
-
# 따옴표 제거
|
157
|
-
answer = answer.gsub('"', '') if answer
|
158
|
-
|
159
|
-
answer ||= title # 응답이 없을 경우 기본 메시지 설정
|
160
|
-
rescue => e
|
161
|
-
puts "Error: #{e.message}"
|
162
|
-
answer = "오류가 발생했습니다."
|
163
|
-
end
|
164
|
-
|
165
|
-
# "생성 중..." 메시지 출력 종료
|
166
|
-
thread.kill
|
167
|
-
|
168
|
-
puts 'API return ==> '
|
169
|
-
puts answer
|
170
|
-
answer
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
|
-
class Chat_content
|
176
|
-
def initialize(api_key, gpt_content_prompt)
|
177
|
-
@api_key = api_key
|
178
|
-
@gpt_content_prompt = gpt_content_prompt
|
179
|
-
end
|
180
|
-
|
181
|
-
def message(content)
|
182
|
-
puts 'Sending request to GPT...(내용 변형 중...)'
|
183
|
-
puts '주의:GPT 특성상 원고 길이가 공백 포함 4천자를 넘기면 오류가 발생할 수 있습니다.'
|
184
|
-
# "키워드 기반 글 생성 중..." 메시지를 별도 스레드로 처리
|
185
|
-
thread = Thread.new do
|
186
|
-
while true
|
187
|
-
print "▶"
|
188
|
-
sleep(3)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
url = 'https://api.openai.com/v1/chat/completions'
|
193
|
-
headers = {
|
194
|
-
'Content-Type' => 'application/json',
|
195
|
-
'Authorization' => 'Bearer ' + @api_key
|
196
|
-
}
|
197
|
-
data = {
|
198
|
-
'model' => 'gpt-4',
|
199
|
-
'messages' => [{
|
200
|
-
"role" => "system",
|
201
|
-
"content" => "너는 매우 친절하고 성의 있게 답변하는 AI 어시스턴트야."
|
202
|
-
},
|
203
|
-
{
|
204
|
-
"role" => "user",
|
205
|
-
"content" => "#{@gpt_content_prompt}\n#{content}"
|
206
|
-
|
207
|
-
}]
|
208
|
-
}
|
209
|
-
|
210
|
-
begin
|
211
|
-
req = HTTP.headers(headers).post(url, json: data)
|
212
|
-
|
213
|
-
response = JSON.parse(req.body.to_s)
|
214
|
-
|
215
|
-
|
216
|
-
if req.status == 429
|
217
|
-
return "API 요청 제한을 초과했습니다. 플랜 및 할당량을 확인하세요."
|
218
|
-
end
|
219
|
-
|
220
|
-
# 응답 데이터에서 안전하게 값 추출
|
221
|
-
answer = response.dig('choices', 0, 'message', 'content')
|
222
|
-
answer ||= (content) # 응답이 없을 경우 기본 메시지 설정
|
223
|
-
rescue => e
|
224
|
-
puts "Error: #{e.message}"
|
225
|
-
answer = "오류가 발생했습니다."
|
226
|
-
end
|
227
|
-
|
228
|
-
# "생성 중..." 메시지 출력 종료
|
229
|
-
thread.kill
|
230
|
-
|
231
|
-
puts 'API return ==> '
|
232
|
-
puts answer
|
233
|
-
answer
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
#############################################gpt############################################
|
240
|
-
|
241
|
-
require 'glimmer-dsl-libui'
|
242
|
-
require 'selenium-webdriver'
|
243
|
-
# require 'webdrivers'
|
244
|
-
require 'iconv'
|
245
|
-
require 'nokogiri'
|
246
|
-
require 'http'
|
247
|
-
require 'json'
|
248
|
-
require 'down'
|
249
|
-
require 'rmagick'
|
250
|
-
require 'fileutils'
|
251
|
-
require 'rest-client'
|
252
|
-
require 'open3'
|
253
|
-
require 'clipboard'
|
254
|
-
require 'crack'
|
255
|
-
require 'uri'
|
256
|
-
require 'cgi'
|
257
|
-
require 'digest'
|
258
|
-
require 'auto_click'
|
259
|
-
require 'rainbow/refinement'
|
260
|
-
include AutoClickMethods
|
261
|
-
using Rainbow
|
262
|
-
include Glimmer
|
263
|
-
|
264
|
-
class Chat
|
265
|
-
def initialize(api_key, gpt_keyword_prompt)
|
266
|
-
@api_key = api_key
|
267
|
-
@gpt_keyword_prompt = gpt_keyword_prompt
|
268
|
-
end
|
269
|
-
|
270
|
-
def message(keyword)
|
271
|
-
puts 'Sending request to GPT...(키워드 기반 글 생성 중...)'
|
272
|
-
|
273
|
-
# "키워드 기반 글 생성 중..." 메시지 출력 스레드
|
274
|
-
thread = Thread.new do
|
275
|
-
while true
|
276
|
-
print "▶"
|
277
|
-
sleep 3
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
url = 'https://api.openai.com/v1/chat/completions'
|
282
|
-
headers = {
|
283
|
-
'Content-Type' => 'application/json',
|
284
|
-
'Authorization' => 'Bearer ' + @api_key
|
285
|
-
}
|
286
|
-
|
287
|
-
# 사용자로부터 받은 입력과 GPT 프롬프트의 토큰 수 계산
|
288
|
-
message_tokens = calculate_tokens(keyword) + calculate_tokens(@gpt_keyword_prompt)
|
289
|
-
|
290
|
-
# 8,192 토큰을 초과하지 않도록 최대 토큰 수를 설정
|
291
|
-
max_response_tokens = [8192 - message_tokens, 4000].min # 8,192 - 입력된 토큰 수, 4,000 이하로 설정
|
292
|
-
|
293
|
-
# 요청 데이터 설정
|
294
|
-
data = {
|
295
|
-
'model' => 'gpt-4',
|
296
|
-
'messages' => [
|
297
|
-
{
|
298
|
-
"role" => "assistant",
|
299
|
-
"content" => "#{keyword}\n#{@gpt_keyword_prompt}"
|
300
|
-
}
|
301
|
-
],
|
302
|
-
'max_tokens' => max_response_tokens # 최대 응답 토큰 설정
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
answer = ''
|
308
|
-
begin
|
309
|
-
req = HTTP.headers(headers).post(url, :json => data)
|
310
|
-
|
311
|
-
# 상태 코드 확인
|
312
|
-
if req.status != 200
|
313
|
-
raise "HTTP Error: #{req.status}, Response Body: #{req.body.to_s}"
|
314
|
-
end
|
315
|
-
|
316
|
-
# 응답 내용 출력 (디버깅용)
|
317
|
-
response = JSON.parse(req.to_s)
|
318
|
-
|
319
|
-
|
320
|
-
# 응답 데이터에서 안전하게 값 추출
|
321
|
-
if response['choices'] && response['choices'][0] && response['choices'][0]['message']
|
322
|
-
answer = response['choices'][0]['message']['content']
|
323
|
-
else
|
324
|
-
raise "Invalid API response format"
|
325
|
-
end
|
326
|
-
rescue => e
|
327
|
-
# 오류 메시지 출력
|
328
|
-
puts "Error occurred: #{e.message}"
|
329
|
-
answer = "오류가 발생했습니다."
|
330
|
-
end
|
331
|
-
|
332
|
-
# "생성 중..." 메시지 출력 종료
|
333
|
-
thread.kill
|
334
|
-
|
335
|
-
# 결과 로그 출력
|
336
|
-
puts "Final API response ==> #{answer}"
|
337
|
-
return answer
|
338
|
-
end
|
339
|
-
|
340
|
-
def calculate_tokens(text)
|
341
|
-
# 간단한 방식으로 텍스트의 토큰 수 계산 (정확도는 다를 수 있음)
|
342
|
-
# OpenAI API는 1토큰이 대략 4글자 정도임
|
343
|
-
text.split(/\s+/).length # 간단한 단어 수로 계산
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
111
|
class Chat_title
|
352
112
|
def initialize(api_key, gpt_title_prompt)
|
353
113
|
@api_key = api_key
|
@@ -2698,7 +2458,7 @@ class Wordpress
|
|
2698
2458
|
puts 'Tethering IP change...'
|
2699
2459
|
|
2700
2460
|
stdout, stderr, status = Open3.capture3('./adb devices')
|
2701
|
-
|
2461
|
+
|
2702
2462
|
if status.success?
|
2703
2463
|
device_id = stdout.split("\n")[1].split("\t")[0]
|
2704
2464
|
puts device_id
|
@@ -2706,42 +2466,53 @@ class Wordpress
|
|
2706
2466
|
# ADB 서버 초기화
|
2707
2467
|
puts 'adb kill-server'
|
2708
2468
|
Open3.capture3('./adb kill-server')
|
2709
|
-
sleep(
|
2469
|
+
sleep(5) # ADB 서버가 안정될 시간을 충분히 주기
|
2710
2470
|
|
2711
2471
|
# 다시 ADB 서버 실행
|
2712
2472
|
puts 'adb start-server'
|
2713
2473
|
Open3.capture3('./adb start-server')
|
2714
|
-
sleep(
|
2474
|
+
sleep(5) # ADB 서버가 안정될 시간을 충분히 주기
|
2715
2475
|
|
2716
2476
|
# 데이터를 끄고 켜기
|
2717
2477
|
puts 'adb -s ' + device_id + ' shell svc data disable'
|
2718
|
-
stdout2, stderr2, status2 = Open3.capture3('./adb -s '+device_id+' shell svc data disable')
|
2719
|
-
|
2478
|
+
stdout2, stderr2, status2 = Open3.capture3('./adb -s ' + device_id + ' shell svc data disable')
|
2479
|
+
puts "stderr: #{stderr2}" unless status2.success? # 오류 출력
|
2480
|
+
sleep(5) # 네트워크가 안정될 시간을 더 줍니다.
|
2720
2481
|
puts 'adb -s ' + device_id + ' shell svc data enable'
|
2721
|
-
Open3.capture3('./adb -s '+device_id+' shell svc data enable')
|
2722
|
-
|
2482
|
+
stdout3, stderr3, status3 = Open3.capture3('./adb -s ' + device_id + ' shell svc data enable')
|
2483
|
+
puts "stderr: #{stderr3}" unless status3.success? # 오류 출력
|
2484
|
+
sleep(5) # 네트워크가 안정될 시간을 더 줍니다.
|
2723
2485
|
puts 'adb ok'
|
2724
2486
|
sleep(8)
|
2725
|
-
|
2487
|
+
|
2488
|
+
# IP 변경 확인을 위한 람다 함수
|
2726
2489
|
robot_ip = lambda do
|
2727
|
-
|
2728
|
-
|
2729
|
-
|
2730
|
-
|
2490
|
+
begin
|
2491
|
+
# IP 변경 확인
|
2492
|
+
http = HTTP.get('https://www.findip.kr/')
|
2493
|
+
noko = Nokogiri::HTML(http.to_s)
|
2494
|
+
|
2495
|
+
current_ip = noko.xpath('/html/body/header/h2').text.strip
|
2496
|
+
if current_ip != @my_ip
|
2497
|
+
@my_ip = current_ip
|
2731
2498
|
puts "IP 변경됨[ #{@my_ip} ]"
|
2732
|
-
|
2733
|
-
puts @my_ip
|
2734
|
-
puts '
|
2735
|
-
sleep(
|
2736
|
-
robot_ip[]
|
2499
|
+
else
|
2500
|
+
puts "현재 IP: #{@my_ip}"
|
2501
|
+
puts 'IP 변경이 감지되지 않았습니다. 다시 시도합니다...'
|
2502
|
+
sleep(5) # 여유롭게 대기 시간 증가
|
2503
|
+
robot_ip[] # 재시도
|
2504
|
+
end
|
2505
|
+
rescue HTTP::ConnectionError => e
|
2506
|
+
puts "네트워크 오류 발생: #{e.message}. 재시도 중..."
|
2507
|
+
sleep(5) # 재시도 간 여유 시간 추가
|
2508
|
+
retry # 재시도
|
2737
2509
|
end
|
2738
|
-
|
2739
|
-
|
2740
|
-
|
2510
|
+
end
|
2511
|
+
robot_ip[] # IP 확인 시작
|
2741
2512
|
else
|
2742
|
-
|
2513
|
+
puts "adb devices 명령어 실행 실패. stderr: #{stderr}"
|
2743
2514
|
end
|
2744
|
-
|
2515
|
+
end
|
2745
2516
|
|
2746
2517
|
|
2747
2518
|
check_success = 1
|
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.
|
4
|
+
version: 0.0.97
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: File to Clipboard gem
|
14
14
|
email: mymin26@naver.com
|