How can I get the graphical output from another program? - python

I'm trying to build my own remote desktop which can be accessed by the browser. My first idea was building a server (with python I would use flask) and including the graphical output of the OS into my html page. Because I thought that that would be difficult/not possible my next plan is to get just the graphical output of one program which I started from the server.
Please tell me how I could do this or how I could start with this project.

This is a daunting task, but I guess this procedure would be a good start for a prototype.
Capture the display using ffmpeg:
Capturing and streaming with ffmpeg while displaying locally
Create a route to view this stream: Streaming MOVIE Python flask
Listen to click/keyboard events on the page and relay them back to source, apply these interactions using a input driver

Related

Uploaded video process by python code on server

I have a python code on a server and if I upload a video from mobile to the server,so How can I provide path of that video to the python code if I want every video should prodceed by the python code
I have doubts that your explanation has truly reflects what you need. First of all servers accept every thing "as it is" as long as the input has the appropriate format for that specific "server". In your case, the video might be a stream, binary, or event encoded data in to a "socket" in your "server". the framework should not matter. So when you have a stream you should be able get it in to your "server" to be processed. If you have problem in that sense, you should try to look first how "servers" accept input. I assume you're knowledgable for that. Let's say you have a nginx server on a linux machine which also has a python included. So your web server should be configured to run in python (Django or something similar). Once you started to upload your file, the content can be passed as async, or sync process in python (I think I should not mention how RESTFull model work on http). When you have the data (stream or static/bulk), you should be able to whatever you want to do with that data.

Run a Python script from a HTML page using nginx on a Raspberry Pi

I've been working on a project recently where basically I need to make a motor spin at certain times throughout the day for a few seconds, that can be customised using your phone.
So far I have followed many tutorials and done a lot of browsing and I've managed to have my Pi zero host its own network(using nginx, hostapd and dnsmasq), which you can connect to on your phone and go to 192.168.4.1 to access an index.html page in /var/www/html/
I also have a Python script which, when run, turns one of the GPIO pins on for a few seconds and then off again, and this GPIO pin is in turn connected to the motor.
The trouble I am having is setting up the rest of the web side, where you are able to connect to the network, go to a page, insert 2 or 3 different times, submit them, and then when it's that time the Python scripts will run.
Since I've set up the pi as a access point, I'm not sure how to reverse it and allow it to connect to wifi again without ruining the access point and current set up, so I'm not sure if there's an easy way to download any packages or modules I may need.
Anyway, any help anyone could give me would be incredibly useful - many thanks!!
Unless you are planning for a production web server, for simple application like display sensor status or control sensor via web page, there is a simpler solution for beginners and for python programmers. Since you are using python, so you don't have to use PHP, and you probably don't need to have Nginx at this stage. There are actually two ways in my experiences to do it.
1) Using http.server
The 'simple way' to serve web page using python based on python standard library http.server, utilising python build-in socket based http server. But it is less intuitive to set it up for GET/POST requests/responses. It is too long to describe it here, but I have a blog post on how to do it here.
2) Using Flask web development micro framework
Flask allows you to setup html template, handling route and run a web server easily within python environment. You need to install Flask package for python web development. The simplest flask python code that addressed your question of serving the data to a web page would be:
from flask import Flask, render_template_string
app = Flask(__name__)
data = 200 #assuming this is the data you want to show in your web page
#app.route('/')
def index():
return render_template_string('''
<h1>My Sensor Web Page</h1>
<p>My sensor reading is {}".format(data))</p>
'''
if __name__ == '__main__':
app.run(debug=True)
Launch your browser and point it to http://localhost:8000, you should see the data to be rendered as webpage per our simple example code.
What you will need is to either import your code into this flask example, or integrate it into the example, and pass the data you want to display to render_template_string function.
I would suggest using a web framework to host the "website". Flask is one that I have used for similar applications. Since this method allows you to directly call python functions in response to http requests it should be fairly easy to implement what you are trying to do.
As a bonus, you can use flask with nginx but I really don't think you need it for this specific application.

invoke python script and populate results on webpage

I created a simple python script which takes a URL as input and once passed will do curl using multiple proxies and show the response code, now I want to create a webpage where others can use(my colleagues) as it will help them too, I want to create simple webpage which let them select set of proxy addresses, and input URL and upon submission, it will run the script on a machine(webserver) and populate the result to webpage using dynatable or datatable frameworks, but am not sure how or if it is possible as I didn't worked much in webserver thing, I want to know what tools I will need and how do I design it.
If python script can be called in terminal(as it needs to run curl) and show result on webpage based on output from script(which I will export to csv file), how can I do that? what to use xampp, wamp, lamp etc ?
You need a framework for this, something that will listen to your request coming from the front-end (webpage), there are tons out there as python framework, you can check bottle framework as a starting point.
So the flow would be something below.
1. from webpage, a request is sent to the backend
2. backend receive the request and run your logic (connecting to some server, computing logic, etc)
3. once backend process is done, backend then send the response to webpage
you can either use a REST approach or use templating functionality of the framework
You will need a request. You can do this in JavaScript with an ajax request there are frameworks to hook it up straight to your python which allow you not to code the JavaScript https://www.w3schools.com/xml/ajax_intro.asp there are many JavaScript frameworks that will make this easier/ shorter to code.

realtime listening GET parameter on python

I had a pi-copter project. My idea to control it is using web page. I have done it using php. But the copter running gyro sensor to makes it stable while flying. So, to run and get data from the sensor, it have to be programmed. I using python to run the sensor. the script will process a control to esc from orientation and from data that I sends using front-end web page.
my question is how python listens GET data from front-end web page?

Access webcam over internet using Python

I have written a program using Python and OpenCV where I perform operations on a video stream in run time. It works fine. Now if I want to publish it on a website where someone can see this using their browser and webcam, how do I proceed?
not really sure what you want to happen but if your going to implement this kind of feature in a website I think you should use a flash application instead of python (or if possible html 5). though your using python on the development of you web app it would only run on the server side instead and the feature you want to use is on a client side so for me it's more feasible to use flash instead to capture the video then after capturing the video you upload it to your server then your python code will do the rest of the process on the server side.

Categories