Home > OS >  how to send data from separate computer to flask app
how to send data from separate computer to flask app

Time:09-08

My use case is I have a flaskapp running The idea is it'll just display a static page (currently using PySimpleGUI) and upon receiving the information sent from the other computer (such as the name for e.g.) then it'll show the name as a QR code. (so perhaps a constant refresh on the GUI and changing upon receiving the data)

The code setup is this way currently

@app.route('/qrcode', methods=['GET'])
def displayQrCode():
    args = request.args 
    name = args.get('name') #
    
    try:
        img = qrcode.make(name)
        img.save('checkin-qrcode.png')
        # Display QR Code
        qrWindowThread = threading.Thread(target=qrCodeWindowShow)
        qrWindowThread.start()
        print(name)
        return 'Success'
    except RuntimeError:
        return 'Error in GET'

However, being new to Flask i am not sure how to send a string from a separate computer running jupyter notebook to this Flask app. Online tutorials show like having a form field page but i wish to not have an user input.

So for instance if the jupyter notebook code sends a post request to the ipaddress:5000 it should ideally show (correct me here: ipaddress:5000/qrcode?name=JohnDoe) so the flask app would retrieve this JohnDoe and display it as a QR code. I can hardcode or manually access this page but how would i have it 'listen' to this /qrcode and then Get the value when it's sent. Or am i misunderstanding it all and I need to do it via another way?

CodePudding user response:

EDIT:

Alright third time lucky, I think I understand what you want now. So your use case is a first computer that is displaying a GUI and running a flask server with an route that can take in a string.

There's a second computer that can send a http request to that route with a name and when that happens you want the GUI on the first computer to refresh to display a QR code of the name.

I'd solve this by having the qrcode route write that name to persistent storage. Could be anything sqlite db, an environment variable, a string in a file.

The first computer running the PySimpleGUI interface poles this persistent storage for changes, and if it sees a change then it renders a new QR code for that name and displays it.

CodePudding user response:

There are multiple ways available to do that:

  1. RESTAPI integration
  2. Realtime data transmission using tornado or etc
  3. Through a base origin for data transmission

Hope you get help with this.

  • Related