# -*- coding: utf-8 -*-
Usage:
add-post <session> <inputfile>
"""
from docopt import docopt
import requests
import json
import os
import time
from datetime import datetime
if __name__ == '__main__':
# 将绑定交互参数
arguments = docopt(__doc__)
session = arguments['<session>']
inputfile = arguments['<inputfile>']
url = "http://xxx"
# print(os.getcwd())
if os.path.isfile(inputfile) == False:
print("找不到此文件:{}".format(inputfile))
exit(0)
# Content-Type类型需要设置为:application/json
headers = {"Content-Type": "application/json", "Cookie": "CNAF_SESSIONID_V2017={}".format(session)}
a = datetime.now()
with open(inputfile, mode='r', encoding='gbk') as f:
for line in f:
# split()默认以空格分隔,此处根据文档中数据进行分隔
list_line = line.split()
time.sleep(1)
data_str = {'name': list_line[0], 'remark': list_line[1]}
# 需要将str文件转换成json对象
r = requests.post(url, json.dumps(data_str), headers=headers)
print(r.text)
b = datetime.now()
# print("{}:{}".format(a, b))
print('Cost {} seconds'.format((b - a).seconds))
# -*- coding: utf-8 -*-
"""
Usage:
miguQuery <session> <class_id> <inputfile> <outputfile>
"""
from docopt import docopt
import requests
import json
import os
import time
from datetime import datetime
if __name__ == '__main__':
# 将绑定交互参数
arguments = docopt(__doc__)
session = arguments['<session>']
class_id = arguments['<class_id>']
inputfile = arguments['<inputfile>']
outputfile = arguments['<outputfile>']
url = "http://xxx"
if os.path.isfile(inputfile) == False:
print("找不到此文件:{}".format(inputfile))
exit(0)
if os.path.isfile(outputfile) == True:
print("文件: {} 已经存在,请保存为另一个名字".format(outputfile))
exit(0)
headers = {"Cookie": "CNAF_SESSIONID_V2017={}".format(session)}
a = datetime.now()
with open(inputfile, mode='r', encoding='utf-8') as f:
for line in f:
# split()默认以空格分隔,此处根据文档中数据进行分隔
time.sleep(1)
data_str = {'classId': class_id, 'content': line}
r = requests.post(url, data_str, headers=headers)
print(r.text)
b = datetime.now()
# print("{}:{}".format(a, b))
print('Cost {} seconds'.format((b - a).seconds))