def main(): options = input(MENU_TEXT) c = Communicator() if options == "1": to_send = input("Type what you want to send\n> ") # turn input into dict to pass through request.post() as json # conversion between dict and json is automatic to_send = {"entry_string": to_send} c.send_recieve(to_send) elif options == "2": print("Type what you want to send. \nType 'q' to quit.") while True: to_send = input("\n> ") if to_send == "q": quit() # turn input into dict to pass through request.post() as json # conversion between dict and json is automatic to_send = {"entry_string": to_send} c.send_recieve(to_send) elif options == "3": c.read_last() elif options == "0": quit() else: print("Option not recognised. Try again.") main()
def index(): """ main view Takes input-string and passes it through the communicator class """ # set response to none response = None # check for http-request if request.method == "POST": # fetch data in request user_input = request.form["user_input"] # put data into python-dict to use as json user_input = {"user_input": user_input} # send through Communicator and store response in 'output' response = Communicator.send_recieve(user_input) # render webapp return render_template("index.html", output=response)