summaryrefslogtreecommitdiff
path: root/instances.py
diff options
context:
space:
mode:
Diffstat (limited to 'instances.py')
-rw-r--r--instances.py37
1 files changed, 20 insertions, 17 deletions
diff --git a/instances.py b/instances.py
index 5996541..bbdfd1f 100644
--- a/instances.py
+++ b/instances.py
@@ -6,10 +6,9 @@ import time
import sys
import psutil
import requests
-import json
import urllib.request
import base64
-
+import simplejson as json
from datetime import datetime
from django.template.loader import render_to_string, get_template
@@ -19,8 +18,7 @@ from R_on_Cloud.settings import PROJECT_DIR
from R_on_Cloud.config import (BIN, API_URL, API_URL_PLOT)
-def execute_code(code, session_id, R_file_id):
- #session_id = self.request.session['session_id']
+def execute_code(code, user_id, R_file_id):
# Check for system commands
system_commands = re.compile(
@@ -38,23 +36,28 @@ def execute_code(code, session_id, R_file_id):
body = {
'code': code,
- 'session_id': session_id,
+ 'user_id': user_id,
'R_file_id': R_file_id,
}
- req = urllib.request.Request(API_URL)
- req.add_header('Content-Type', 'application/json; charset=utf-8')
+ headers = {
+ "Content-Type": "application/json",
+ "Accept": "application/json",
+ }
jsondata = json.dumps(body)
- jsondataasbytes = jsondata.encode('utf-8')
- req.add_header('Content-Length', len(jsondataasbytes))
- result = urllib.request.urlopen(req, jsondataasbytes)
- result = result.read().decode("utf8")
- output = json.loads(result)["output"]
- graph_exist = json.loads(result)["graph_exist"]
- graph_path = API_URL_PLOT + "?session_id=" + session_id +"&R_file_id="+ R_file_id
+ #jsondata = urllib.parse.urlencode(body)
+ #print(jsondata)
+
+ result=requests.post(API_URL, json=jsondata, headers=headers)
+ output = result.json()
+ output_data= json.dumps(output['data'])
+ output_error = json.dumps(output['error'])
+ graph_exist = ""
+ graph_path = ""
data = {
- 'output': output,
- 'graph_exist': graph_exist,
- 'graph_path': graph_path,
+ 'output': json.loads(output_data),
+ 'error': json.loads(output_error)
+ #'graph_exist': graph_exist,
+ #'graph_path': graph_path,
}
return data