-
Notifications
You must be signed in to change notification settings - Fork 1
/
send_json.py
46 lines (35 loc) · 1.41 KB
/
send_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import pathlib
import datetime
import requests
import my_logger
def send_json_to_model(model_json_file):
#latest file 10
model_api = "http://10.0.2.208:8000/keyword"
try:
res = requests.post(model_api, json=model_json_file)
assert res.status_code == 200 or res.status_code == 201, \
"Requset Failed check out header or request parameter"
return res
except Exception as e:
logger.warning(e)
def send_json_to_service(json_data):
service_api = 'http://10.0.2.208:8080/service/modeling/'
try:
res = requests.post(service_api, json=json_data)
assert res.status_code == 200 or res.status_code == 201, \
"Requset Failed check out header or request parameter"
return res
except Exception as e:
logger.warning(e)
if __name__ == '__main__':
logger = my_logger.create_logger('Api')
JSON_PATH = pathlib.Path(__file__).parent.joinpath("./json/")
with open(JSON_PATH.joinpath('data_to_model.json'), "r") as json_file:
model_json_file = json.load(json_file)
json_data = send_json_to_model(model_json_file).json()
now_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
json_data['date'] = now_date
with open(JSON_PATH.joinpath('data_to_service.json'), "w") as json_file:
json.dump(json_data, json_file, indent=4)
send_json_to_service(json_data)