e0qdk@reddthat.comtoProgramming@programming.dev•Where do I start to make something like this?
1·
3 months agoI wrote something like this before for academic researchers to load data sets on display walls by using their cellphones. I approached it by building a simple website. When the user logs in, they’d see a table of entries (from a directory listing on a shared file server that they could drop their data sets onto) and could click a button that made a form post to the server which caused it to run whichever programs were needed to load the data set they wanted (or run a couple of other handy commands – like turning the monitors on/off, etc).
You can do something like that too in Python if you want:
- Learn how to start and stop programs from Python scripts. This can be done with the built-in
subprocess
library. If you know how to launch the programs you want from the command line, it shouldn’t be too hard to figure out how to do it from Python by reading the documentation. It will take some more effort to figure out how to interact with it (e.g. to stop it from user input) without blocking your script, but this can be done. - Learn how to write a simple program that can respond to HTTP requests in Python. There are a number of libraries like tornado, flask, cherrypy, etc. that can do this. Pick one, read the documentation, and write a tiny page that allows you to submit a form and then trigger an action on the server in response to an HTTP POST. You should be able to interact with it by pointing the browser on your computer to
localhost
(possibly plus a port) or from on your LAN by putting the IP of your computer into the address bar. - Figure out how you’re going to organize the entries you want to be able to load. You could just do something trivial like putting the files in known folders and running
os.listdir
, or something more involved like tracking the entries with a spreadsheet or database or JSON file that lets you associate custom metadata with each entry (like a custom name to show or an icon to display or when it was last launched, etc.) - Generate a web page based on that data collection. I recommend using templating – e.g. with mustache, or jinja, etc. Basically you write some HTML-like text that lets you indicate places to fill in data from your program and it will do the conversion of symbols like
<
into<
that are needed for HTML output and also repeat patterns using entries from lists you provide to build the rows of tables and such for you. - Set up some security (e.g. a simple log in system) and polish it up as much as you care to do.
Good luck and have fun!
You can do this by configuring an HTTP server (e.g. Apache) to listen on port 80 and/or 443 (HTTP and HTTPS standard ports, respectively) and select which site to serve based on the name of the site requested. Apache documentation for this feature is here: https://httpd.apache.org/docs/2.4/vhosts/name-based.html
Note the sample config snippet showing how to set up a simple static site serving both
www.example.com
andother.example.com
usingServerName
in aVirtualHost
to select between them.You can also have Apache match a pattern in the URL and reverse proxy to another HTTP server – that can just be another program on the same computer listening on a different port, or could be on another computer entirely. See the simple reverse proxy config example on this page for a starting point: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html (Note also that you probably don’t need anything further down that page – e.g. the load balancer and failover stuff is not likely to be useful to you for a small personal project.)
Other popular HTTP servers can do this too; I just happen to have done it with Apache before.