Skip to content

Commit ca7415b

Browse files
committed
1. 命令行工具改为从剪切板读取内容,解决内容过长控制台不能输入问题
2. 浏览器添加xhr_data函数
1 parent d5a0cbe commit ca7415b

7 files changed

Lines changed: 49 additions & 31 deletions

File tree

feapder/commands/cmdline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ def execute():
4343
shell.main()
4444
else:
4545
_print_commands()
46+
47+
48+
if __name__ == "__main__":
49+
execute()

feapder/commands/create/create_cookies.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,26 @@
99
"""
1010

1111
import json
12-
import sys
12+
13+
import pyperclip
1314

1415
from feapder.utils.tools import get_cookies_from_str, print_pretty
1516

1617

1718
class CreateCookies:
1819
def get_data(self):
1920
"""
20-
@summary: 从控制台读取多行
21+
@summary: 从剪切板中读取内容
2122
---------
2223
---------
2324
@result:
2425
"""
25-
print("请输入浏览器cookie (列表或字符串格式)")
26-
data = []
27-
while True:
28-
line = sys.stdin.readline().strip()
29-
if not line:
30-
break
26+
input("请复制浏览器cookie (列表或字符串格式), 复制后按任意键读取剪切板内容\n")
3127

32-
data.append(line)
28+
text = pyperclip.paste()
29+
print(text + "\n")
3330

34-
return "".join(data)
31+
return text
3532

3633
def create(self):
3734
data = self.get_data()

feapder/commands/create/create_json.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@email: boris_liu@foxmail.com
99
"""
1010

11-
import sys
11+
import pyperclip
1212

1313
import feapder.utils.tools as tools
1414

@@ -21,10 +21,14 @@ def get_data(self):
2121
---------
2222
@result:
2323
"""
24-
print("请输入需要转换的内容: (xxx:xxx格式,支持多行)")
24+
input("请复制需要转换的内容(xxx:xxx格式,支持多行),复制后按任意键读取剪切板内容\n")
25+
26+
text = pyperclip.paste()
27+
print(text + "\n")
28+
2529
data = []
26-
while True:
27-
line = sys.stdin.readline().strip().replace("\t", " " * 4)
30+
for line in text.split("\n"):
31+
line = line.strip().replace("\t", " " * 4)
2832
if not line:
2933
break
3034

@@ -49,4 +53,4 @@ def create(self, sort_keys=False):
4953
else:
5054
json[result[0]] = result[1].strip()
5155

52-
print(tools.dumps_json(json, sort_keys=sort_keys))
56+
print(tools.dumps_json(json, sort_keys=sort_keys))

feapder/commands/create/create_table.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
@email: boris_liu@foxmail.com
99
"""
1010

11-
import sys
1211
import time
1312

13+
import pyperclip
14+
1415
import feapder.setting as setting
1516
import feapder.utils.tools as tools
1617
from feapder.db.mysqldb import MysqlDB
@@ -62,18 +63,15 @@ def get_data(self):
6263
---------
6364
@result:
6465
"""
65-
data = ""
66-
while True:
67-
line = sys.stdin.readline().strip()
68-
if not line:
69-
break
70-
data += line
66+
input("请复制json格式数据, 复制后按任意键读取剪切板内容\n")
7167

72-
return tools.get_json(data)
68+
text = pyperclip.paste()
69+
print(text + "\n")
70+
71+
return tools.get_json(text)
7372

7473
def create(self, table_name):
7574
# 输入表字段
76-
print('请输入表数据 json格式 如 {"name":"张三"}\n等待输入:\n')
7775
data = self.get_data()
7876

7977
if not isinstance(data, dict):
@@ -98,17 +96,21 @@ def create(self, table_name):
9896

9997
comment = input("%s : %s -> comment:" % (key, key_type))
10098

101-
other_key += "`{key}` {key_type} COMMENT '{comment}',\n ".format(
102-
key=key, key_type=key_type, comment=comment
99+
other_key += (
100+
"`{key}` {key_type} COMMENT '{comment}',\n ".format(
101+
key=key, key_type=key_type, comment=comment
102+
)
103103
)
104104

105105
print("\n")
106106

107107
while True:
108108
is_need_batch_date = input("是否添加batch_date 字段 (y/n):")
109109
if is_need_batch_date == "y":
110-
other_key += "`{key}` {key_type} COMMENT '{comment}',\n ".format(
111-
key="batch_date", key_type="date", comment="批次时间"
110+
other_key += (
111+
"`{key}` {key_type} COMMENT '{comment}',\n ".format(
112+
key="batch_date", key_type="date", comment="批次时间"
113+
)
112114
)
113115
break
114116
elif is_need_batch_date == "n":
@@ -132,4 +134,5 @@ def create(self, table_name):
132134
)
133135
print(sql)
134136
self._db.execute(sql)
135-
print("\n%s 创建成功" % table_name)
137+
print("\n%s 创建成功" % table_name)
138+
print("注意手动检查下字段类型,确保无误!!!")

feapder/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ redis-py-cluster>=2.1.0
1414
cryptography>=3.3.2
1515
urllib3>=1.25.8
1616
loguru>=0.5.3
17-
influxdb>=5.3.1
17+
influxdb>=5.3.1
18+
pyperclip>=1.8.2

feapder/utils/webdriver.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
import queue
1414
import threading
15-
from typing import Optional
15+
from typing import Optional, Union
1616

1717
from selenium import webdriver
1818
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
@@ -343,10 +343,18 @@ def xhr_response(self, xhr_url_regex) -> Optional[XhrResponse]:
343343
response = XhrResponse(request, **data["response"])
344344
return response
345345

346+
def xhr_data(self, xhr_url_regex) -> Union[str, dict, None]:
347+
response = self.xhr_response(xhr_url_regex)
348+
if not response:
349+
return None
350+
return response.content
351+
346352
def xhr_text(self, xhr_url_regex) -> Optional[str]:
347353
response = self.xhr_response(xhr_url_regex)
348354
if not response:
349355
return None
356+
if isinstance(response.content, dict):
357+
return json.dumps(response.content, ensure_ascii=False)
350358
return response.content
351359

352360
def xhr_json(self, xhr_url_regex) -> Optional[dict]:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"urllib3>=1.25.8",
5151
"loguru>=0.5.3",
5252
"influxdb>=5.3.1",
53+
"pyperclip>=1.8.2",
5354
]
5455

5556
memory_dedup_requires = ["bitarray>=1.5.3"]

0 commit comments

Comments
 (0)