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