Skip to content

Commit d45f768

Browse files
author
caofanCPU
committed
support concurrent request, but somewhere has bug in httpie util.
1 parent ee5f738 commit d45f768

File tree

4 files changed

+81
-37
lines changed

4 files changed

+81
-37
lines changed

auto/ID.csv

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
1-
55746186
2-
55746186
3-
55746186
4-
55746186
5-
55746186
6-
55746186
7-
55746186
8-
55905267
9-
55905267
10-
55905267
11-
55894967
12-
55894967
13-
55894967
14-
55894967
15-
55894967
16-
56000896
17-
56000896
18-
56699543
19-
56699543
20-
56707106
1+
1
2+
2
3+
3
4+
4
5+
5
6+
6
7+
7
8+
8
9+
9
10+
10
11+
11
12+
12
13+
13
14+
14
15+
15
16+
16
17+
17
18+
18
19+
19
20+
20
21+
21
22+
22
23+
23
24+
24
25+
25
26+
26
27+
27
28+
28
29+
29
30+
30
31+
31
32+
32
33+
33
34+
34
35+
35
36+
36
37+
37
38+
38
39+
39
40+
40
41+
41
42+
42
43+
43
44+
44
45+
45
46+
47+
48+
49+
50+
51+
52+
53+

auto/batchHandler.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
import datetime
34
import json
45
import ssl
5-
import sys
66
import subprocess
7+
import sys
78
import time
8-
import pandas as pd
9+
from concurrent.futures.thread import ThreadPoolExecutor
910

11+
import pandas as pd
1012
import requests
1113

1214
# 屏蔽HTTPS证书校验, 忽略安全警告
@@ -18,22 +20,28 @@
1820
hot_reload = True
1921
cmd = "http"
2022
no_ca = "--verify=no"
21-
httpie_allow_view = {
22-
"-v": "显示请求详细信息",
23-
"-h": "显示请求头",
24-
"-b": "显示请求Body",
25-
"-d": "响应结果保存至TXT",
26-
"": "默认"
27-
}
23+
httpie_allow_view = {"-v": "显示请求详细信息", "-h": "显示请求头", "-b": "显示请求Body", "-d": "响应结果保存至TXT", "": "默认"}
2824
httpie_view = None
25+
# 并发数
26+
max_concurrent = 64
27+
concurrent = 1
2928
try:
3029
if len(sys.argv) > 1:
3130
if httpie_allow_view.get(sys.argv[1]) is not None:
3231
httpie_view = sys.argv[1]
3332
else:
3433
print("输入参数有误, 仅支持如下参数: -v显示请求详细信息|-h显示请求头|-b显示请求Body|-d响应结果保存至TXT")
34+
if len(sys.argv) > 2:
35+
try:
36+
input_concurrent = int(sys.argv[2])
37+
if input_concurrent > 1:
38+
concurrent = min(input_concurrent, max_concurrent)
39+
except Exception as e:
40+
print("并发数设置范围[1, {}], 默认1".format(max_concurrent))
41+
print(e)
3542
except Exception as e:
3643
print(e)
44+
executor = ThreadPoolExecutor(max_workers=concurrent)
3745

3846

3947
def httpie_cmd(id):
@@ -55,11 +63,13 @@ def httpie_cmd(id):
5563
httpie_params.append(httpie_view)
5664
httpie_params.extend([method, url, headers, body])
5765
httpie = joiner.join(httpie_params)
58-
print(httpie)
59-
print("当前ID: ", id)
66+
# print(httpie)
67+
executeStartTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
6068
# 延时执行
61-
time.sleep(0.05)
69+
# time.sleep(0.05)
6270
subprocess.call(httpie, shell=True)
71+
executeEndTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
72+
return "当前[ID={}, [executeStartTime={}], [executeEndTime={}]".format(id, executeStartTime, executeEndTime)
6373

6474

6575
def load_request_headers(headers, hot_reload):
@@ -113,15 +123,16 @@ def auto_login():
113123
f.write(cookie)
114124
# JSON标准格式
115125
response_body = json.dumps(response.json(), ensure_ascii=False, indent=4)
116-
print(response_body)
126+
print("\n执行登录响应BODY结果: \n" + response_body)
117127
return cookie
118128

119129

120130
def main():
121131
# 首先登陆一次
122132
auto_login()
123-
for id in load_data():
124-
httpie_cmd(id)
133+
ids = load_data()
134+
for result in executor.map(httpie_cmd, ids):
135+
print(result)
125136

126137

127138
if __name__ == '__main__':

auto/cookie.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'Cookie:_r=ihJwwY0cYz49sr6PMLsFz0BZpRyQxkFQVg2iP9QJYR3xbG0Dl3LHiONXx0N5rlQd|HXj5A8Lr5cw=; Max-Age=2592000; Expires=Sat, 09-May-2020 08:53:08 GMT; Domain=testa.huitong.com; Path=/; HttpOnly, _a=HUQD4RRBySY9sr6PMLsFz0BZpRyQxkFQVg2iP9QJYR3xbG0Dl3LHiJTWI8zUke//55U6X+1Po33WN5X4+xDCD63RgLyKuIbo|C8IWYbAVYXA=; Max-Age=7200; Expires=Thu, 09-Apr-2020 10:53:08 GMT; Domain=emp.testa.huitong.com; Path=/; HttpOnly, _a=HUQD4RRBySY9sr6PMLsFz0BZpRyQxkFQVg2iP9QJYR3xbG0Dl3LHiJTWI8zUke//55U6X+1Po33WN5X4+xDCD63RgLyKuIbo|C8IWYbAVYXA=; Max-Age=7200; Expires=Thu, 09-Apr-2020 10:53:08 GMT; Domain=emp2.testa.huitong.com; Path=/; HttpOnly'
1+
'Cookie:_r=ihJwwY0cYz49sr6PMLsFz0BZpRyQxkFQfqtQSrOxQNgjrbvfiad33YRFMbWVOFY7|Bt4XvnwQD0g=; Max-Age=2592000; Expires=Sat, 16-May-2020 18:27:59 GMT; Domain=testa.huitong.com; Path=/; HttpOnly, _a=HUQD4RRBySY9sr6PMLsFz0BZpRyQxkFQfqtQSrOxQNgjrbvfiad33aJ+8ZAs65Qj55U6X+1Po31adyYgUMNqH1vXuurqEFhH|2huAgBlVNhQ=; Max-Age=7200; Expires=Thu, 16-Apr-2020 20:27:59 GMT; Domain=emp.testa.huitong.com; Path=/; HttpOnly, _a=HUQD4RRBySY9sr6PMLsFz0BZpRyQxkFQfqtQSrOxQNgjrbvfiad33aJ+8ZAs65Qj55U6X+1Po31adyYgUMNqH1vXuurqEFhH|2huAgBlVNhQ=; Max-Age=7200; Expires=Thu, 16-Apr-2020 20:27:59 GMT; Domain=emp2.testa.huitong.com; Path=/; HttpOnly'

auto/excuteUrl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"url": "https://live.testa.huitong.com/api/v100/live/employee/upload/dibblingVideo/detail",
2+
"url": "http://localhost:8127/ruok",
33
"method": "POST",
44
"headers" : [
55
"Content-Type:application/json",

0 commit comments

Comments
 (0)