def box(): if request.method == 'POST': resp_json = request.get_json() print(resp_json) to_convert = resp_json['text'] ddown = resp_json['ddown'] if ddown == 'Python': py_list = c2p.convert(to_convert) pycode = '' for i in py_list: print(i, end='') pycode += i time.sleep(1) return json.dumps({"response": pycode}), 200 elif ddown == 'PHP': php_code = ptp.convert(to_convert + '\n') time.sleep(1) return json.dumps({"response": php_code}), 200 else: return json.dumps( {"response": "Language under development. Try again later!"}), 200
def transform_view(): request_file = request.files['data_file'] if not request_file: return "No file" file_contents = request_file.stream.read().decode("utf-8") result = transform(file_contents) print(result) if '#incude' in result: py_list = c2p.convert(result) pycode = '' for i in py_list: print(i, end='') pycode += i #print(pycode) response = make_response(pycode) response.headers[ "Content-Disposition"] = "attachment; filename=converted_py_code.py" time.sleep(0.8) return response else: php_code = ptp.convert(result + '\n') response = make_response(php_code) response.headers[ "Content-Disposition"] = "attachment; filename=converted_php_code.php" time.sleep(0.8) return response
def box(): if request.method == 'POST': resp_json = request.get_json() to_convert = resp_json['text'] py_list = c2p.convert(to_convert) pycode='' for i in py_list: print(i,end='') pycode+=i time.sleep(2) return json.dumps({"response": pycode}), 200
import c2p c_code = ''' #include<iostream> #include<conio.h> void main() { int n,a,b,answer; cin>>n; cin>>a; cin>>b; for (int x = 2; x<n; x+2) { answer=(a+b)/x; cout<<answer; } getch() }''' py_list = c2p.convert(c_code) for i in py_list: print(i, end='')