Jira Webhooks allows the user to specify the URL of an application that will receive data, in json format, when an event occurs. For example when an issue is updated in Jira. I want to create a python script that will receive this data and print it out. How is the best way to create this python script?
There are many ways to skin a cat, but basically you need a Web server, which can receive POST requests and knows how to read corresponding parameters.
Several possibilities:
Write simple script using builtin SimpleHTTPServer
Use some web framework (Django, Flask)
Deploy your python script to AWS Lambda and configure API Gateway
And here is an example application from Atlassian which can help you get started.
Related
I have a Flask Web Application that is periodically receiving JSON information from another application via HTTP POST.
My Flask Web Application is running on a CentOS 7 Server with Python 2.7.X.
I am able to parse the fields from this received JSON in the Flask Web Application and get some of the information that interests me. For example: I get some JSON input and extract an "ID":"7" field from it.
What I want to do now is run a perl script from within this Flask Web Application by using this "ID":"7".
Running 'perl my_perl_script.pl 7' manually on the command line works fine. What I want is for the Flask Web Application to perform this automatically whenever it receives an HTTP POST, by using the specific ID number found in this POST.
How can I do that in Flask?
Is it a good idea to do it with a subprocess call or should I consider implementing queues with Celery/rq? Or maybe some other solution?
I think the perl script should be invoked as a separate Linux process, independent of the Flask Web Application.
Thank you in advance :)
Sub,
I vote yes on subprocess, here's a post on SO about it. Control remains with Flask that way. An alternative might be to code a perl script that watchdogs for a trigger event depending on your needs, but that would put more of the process control on the perl side of things and less efficient use of resources.
I am doing a Spotipy script that I want to automize and put it on a server.
By "automize" I mean that for the authentification I don't want to have to copy/paste the open URL (I'm using Authorization Code Flow), is it possible? Or maybe there is a way to catch that opened URL and paste it automatically to the program on the server?
Thank you.
If I understand you correctly:
You can use Flask: http://flask.pocoo.org/, which is a microframework for serving applications (your scripts).
This way, every time you go to URL on your browser (Flask default is localhost:5000), authorization code will run automatically, and you can then be redirected to your served pages, as long as you have templates (html) for them.
Here's an example of how you can implement one app:
https://github.com/datademofun/spotify-flask
And here's a Walkthrough of Authorization Code Flow using Flask and Python, with the Spotify API:
https://github.com/drshrey/spotify-flask-auth-example
I am trying to create a daemon python application which will get emails from outlook server using Microsoft outlook graph API. They have provided excellent tutorial and documentation on how to get it done for python app like django and flask. But I want to create daemon script which can get access code without using web interface(which was used in django).
Note: This app will only collect email from single email and will feed it to db.
Any help is appriciated.
It really depends on what kind of security you need. You can have your daemon/service authenticate with username/password directly, or you can have it authenticate with a certificate.
There are several different authentication scenarios, take a look at the docs page.
Either way, you need to register your daemon as an app in Azure and give it permissions to the Outlook API, just as if it were a web app.
Actual situation:
The client downloads a small pythonscript that is executable.
The client executes it. The script gathers information from the computer and sends the data to the webserver viĆ POST-Method.
Wanted Situation:
After the webserver recived the data, it should forward the information to the website-session of the client. And the website should display the information.
This is a visual example of the principle:
There is also a example of this principle on Can You Run It.
How can I realize this?
A common way of implementing this is using a RESTful API. Basically the API does not care if the request is from a script or web browser, it just passes data structures to and from clients. The only tricky part to your example is when there are multiple users involved because a secret must be shared between the browser and script. I believe Can You Run It puts this unique secret into the program they ask you to download.
Look into Django Rest Framework for examples of how to implement this.
I have a long-running process written in Python 2.7 that I would like to send KML files to my GWT application asynchronously as the KML files are generated.
I have been trying to determine what Python web framework I could use as the back-end with the Python process that could possibly allow the webapp to be hosted on Google AppEngine.
I was able to write a simple python webserver using Cherrypy that sent the kml using JSON from the back-end to GWT using an http request; however, I would like the files to be sent to GWT as they are generated since it may be several minutes between each one. What would be a relatively simple but effective way to achieve this? (Comet? Long-polling? Websockets?)
After researching more python web frameworks, I started experimenting with Tornado because it is non-blocking and seems like it could return data as it is generated possibly using long-polling as mentioned in this answer. However, it looks like GAE requires WSGI which would not allow a Tornado webserver to be non-blocking.
I have read answers to similar questions such as this one. However, I am not sure if updates in web frameworks, GWT, or GAE has changed what is the best option today, or whether some of these answers apply to my case.
What Python web framework would you recommend I use to send data to my asynchronous GWT app using long-polling or another method relatively simply? Could I use this web framework with GAE, or would I need to use something else?
If I understood the problem correctly you might don't need any special framework and you can solve it with what you have: Tasks API and Channel API.
With Tasks API you can perform long task and when the task is complete you can get a notification. You can combine it with the Channel API to push messages directly to the client when a particular task is complete.
You could use also the deferred library to simplify your life with tasks and maybe even using the PubNub for your push notifications, since the setup is easier and you can have many subscribers at the same time.