bercall.blogg.se

Python 2.7.9 http.server
Python 2.7.9 http.server










  1. #PYTHON 2.7.9 HTTP.SERVER ARCHIVE#
  2. #PYTHON 2.7.9 HTTP.SERVER CODE#
  3. #PYTHON 2.7.9 HTTP.SERVER TV#
  4. #PYTHON 2.7.9 HTTP.SERVER WINDOWS#

The Python script and HTML/JS template are meant to be a starting-point. You might add sound and other HTML elements. Other changes that you might choose to make could include ordering the list of images based on filename, timestamp, or some other characteristic. You are encouraged to edit the template.htm file to accommodate your needs. I tried to center the images with some CSS, but I wasn’t able to vertically-center them. You can change the viewing frequency by changing the delay_millis variable in the Python script.

#PYTHON 2.7.9 HTTP.SERVER TV#

Your TV should now be displaying your slideshow. After you click the “Cast” icon in Chrome, you should be able to choose your Chromecast device as a receiver of the tab’s contents. If you supplied your own image files, you should see them every 10 seconds. Ten seconds later, you should see the other one. To view the slideshow, bring up the Chrome browser and visit the address: You should see one of the two JPEG files. The $$2 pseudo-variable has been replaced with the value in the Python script’s variable named html.Īfter the index.html file is created, the build-in Python web-server is started. Note that the $$1 pseudo-variable from “template.htm” has been replaced with the value of Python script’s variable named delay_millis. The generated file “index.html” would look something like this: When executed in the current directory with the file “template.htm” present and the “img” directory containing the two previously-mentioned image files: Httpd = SocketServer.TCPServer(("", 80), Handler) Handler = SimpleHTTPServer.SimpleHTTPRequestHandler With open("index.html","w") as indexfile: Payload=string.replace(payload,"$$2",html) With open('template.htm',"r") as tplfile:

#PYTHON 2.7.9 HTTP.SERVER CODE#

Here is the Python code to generate the file “index.html” in the current directory based on “template.htm”.

#PYTHON 2.7.9 HTTP.SERVER ARCHIVE#

zip archive mentioned earlier in the “img” directory: “one.jpg” and “two.jpg”. Image files must be placed in a directory named “img” immediately underneath the current directory. When all images are exhausted, the process begins at the start of the list. After the specified delay, the SRC attribute will change to the next image name in the list. When the above script loads, it will set the lone IMG tag’s SRC property to the name of the first image in the list. $$2 will be replaced with a JavaScript array containing string-literals that specify the names of each image file. $$1 will be replaced with the desired time delay in milliseconds. Those identifiers will be replaced with other content by the Python script. Please note the pseudo-variables $$1 and $$2 in the above source. Let’s first take a look at the HTML template file named “template.htm” : I knew that it would be relatively straightforward to implement the HTML-formatting portion of the script in Python and the built-in web-server would lend itself to serving up the content. Here’s the Github repository for the code: The script would then function as a web-server, facilitating the requests for images at regular intervals.Īll of the mail source files and referenced image files below can be found in the following archive: I wanted to create a script that would read a directory of images and would then generate an HTML file with some embedded JavaScript to cycle through those images. I would need that tab to utilize a web page that would display a set of images in rotation. Although I implemented it on Windows, the code is intended to be reusable on OS/X, Linux, or other OS’s that support Casting the contents of a browser tab. When one installs the “Cast” extension to Chrome, any tab in the browser can be transmitted to the Chromecast device for viewing on the television.

#PYTHON 2.7.9 HTTP.SERVER WINDOWS#

I thought it would be nice to be able to arrange my own slideshow using Chrome on my Windows computer. It pulls photographic images from someplace ( presumably from a Chromecast web page ) and displays them in succession. I like the “screen saver” function that’s built in when the device isn’t in use. I bought a Google Chromecast device a few days ago.












Python 2.7.9 http.server