-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapicalls.py
46 lines (37 loc) · 2.12 KB
/
apicalls.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 os
#import requests
import subprocess
#from subprocess import DEVNULL, STDOUT, check_call
import json
import commons_proj as cproj
#Specify a URL that resolves to your workspace
URL = "http://127.0.0.1:8000/"
fname = 'apicalls.py'
print(f"- {fname}. -->")
#res1_greetings=subprocess.run(['curl', URL+'?user=esm'],capture_output=True).stdout
res1_greetings = subprocess.Popen('curl ' + URL +'?user=esm', shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0]
print(f"- res1_greetings:\n{res1_greetings}")
#res2_prediction=subprocess.run(['curl', URL+'prediction?dirtype=test_data_path&filename=testdata.csv'],capture_output=True).stdout
res2_prediction = subprocess.Popen('curl ' + URL+'prediction?dirtype=test_data_path\&filename=testdata.csv', shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0]
print(f"- res2_prediction:\n{res2_prediction}")
#res3_scoring=requests.get(URL+'scoring').content
res3_scoring = subprocess.Popen('curl ' + URL +'scoring', shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0]
print(f"- res3_scoring:\n{res3_scoring}")
#res4_summarystats=requests.get(URL+'summarystats').content
res4_summarystats = subprocess.Popen('curl ' + URL +'summarystats', shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0]
print(f"- res4_summarystats:\n{res4_summarystats}")
# res5_diagnostics=requests.get(URL+'diagnostics').content
res5_diagnostics = subprocess.Popen('curl ' + URL +'diagnostics', shell=True, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0]
print(f"- res5_diagnostics:\n{res5_diagnostics}")
responses = {'greetings': res1_greetings,
'prediction': res2_prediction,
'scoring': res3_scoring,
'summarystats': res4_summarystats,
'diagnostics': res5_diagnostics
}
file_name = 'apireturns_'+ cproj.config['output_model_path'] + '.json'
file_path = os.path.join(os.getcwd(), cproj.config['output_model_path'], file_name)
with open(file_path, 'w') as fp:
json.dump(responses, fp, indent=4)
print(f"- json.dump file_name: {file_name}")
print(f"- {fname}. <--")