0

I have a URL of specific structure

"http://xyzabc.in/testing.aspx?mobile=[xxxxxxxxxx]&Operator=[xxxxxxxxxx]&Time_Stamp=[xxxxxxxxxx]".

The 3rd party vendor will provide me the details over this URL. How can I read the data (mobile, operator and time_stamp) from the URL ?

My program must keep on listening to that url endlessly.

I want to do it in python. Do I need to have a web server at my end ? If so, which one is easier ? Django or Flask ? (Please provide code snippets as I am new to web requests handling in python).

CIsForCookies
  • 12,097
  • 11
  • 59
  • 124

1 Answers1

0

If you just want a simple server, Flask will be better.

First, install Flask:

pip install Flask

If you want more detaild instructions, you can check that tutorial: https://flask.palletsprojects.com/en/1.1.x/installation/

This is the basic template of a the Flask app that you want:

from flask import Flask
from flask import request

app = Flask(__name__)

@app.route('/testing', methods=['GET'])
def testing():
    mobile = request.args.get('mobile')
    operator = request.args.get('Operator')
    time_stamp = request.args.get('Time_Stamp')
    
    print(mobile)
    print(operator)
    print(time_stamp)

    return 'Success!'

This code will wait for a GET request on yourdomain.com/testing, and will print the given parameters "mobile", "Operator" and "Time_stamp".

To run:

  1. Save it in a .py file, make sure not to call it flask.py, so it will not conflict with Flask.
  2. Run export FLASK_APP=hello.py on linux, or set FLASK_APP=hello.py on Windows (CMD). make sure to replace hello.py with the name that you called your program in the previous step.
  3. Run flask run.

Now, your server will listen on http://localhost:5000.

Enjoy!

Aviad
  • 142
  • 2
  • 8
  • Hey thanks for the support. The server is up and running !! But I don't see any output when I invoke that URL from a different browser/machine. Any idea ? – user1626000 Apr 12 '21 at 10:59
  • You are welcome! What do you mean by "any output"? Do you get an error? Or an empty reponse? Or just the browser doesn't connect? – Aviad Apr 12 '21 at 12:59
  • And to connect from another machine, use that guide: https://stackoverflow.com/a/7027113/9735208. Just keep in mind that if you just run the server on your computer, it will not be visible from a different network, unless you configure port forwarding. – Aviad Apr 12 '21 at 13:00