Answered

How to run my python script only when new response form requests.get is received?

  • 22 February 2022
  • 4 replies
  • 325 views

I wrote a application with the following logic:

 

1) Fetch Data with API2) Preprocess the Data3) Start topic modeling4) Create report and include data5) Handle final pdf report (send, show in browser ...)

 

Now i only want to start this 5 steps when a new response is received. 

 

So far the script works, but only processes the response when i manually run the script on my system.

 

I also tried using pm2 for running the script like a daemon thread. However, even the script (process) runs forever, it loops over the 5 steps over and over again for the same response. But i want to stop the 5 steps after every individual response.

 

My desired architecture should look like that:

 

if new response:    1) Fetch Data with API    2) Preprocess the Data    3) Start topic modeling    4) Create report and include data    5) Handle final pdf report (send, show in browser ...)else:    wait for new reponse …

 

Any help is appreciated.

 

EDIT in title* form not form

icon

Best answer by pgphi 24 February 2022, 21:20

View original

4 replies

Userlevel 7
Badge +5

@mathio do you happen to know an answer to this? :grinning:

Userlevel 7
Badge +5

@Liz sorry I do not know Python :) 

@pgphi maybe you could expose your script on a URL and use Webhooks API? Or you could store the last processed response and use the after query parameter when retrieving responses via API.

Thank you @Liz and @mathio.

I used the Webhook API and set up an endpoint with flask (python web-framework). This worked. @mathio i also will look into the after query approach - thank you both!

Userlevel 7
Badge +5

Glad to hear that worked, @pgphi !!

Reply