import base64

timeout = input("Please enter the desired timeout in seconds between slides. ")
delay = int(timeout)*1000
str_delay = str(delay)
imagefile = input("Please enter the image you would like to add (requires the full path). If complete enter Q. ")

imginfo = ""

while imagefile != "Q":
    try:
        with open(imagefile, "rb") as binary_imagefile:
            imgBin = base64.b64encode(binary_imagefile.read())
            imgBin = imgBin.decode('UTF-8')
            imginfo = imginfo+"""
                <div class="mySlides fade">
                <img src="data:image/png;base64,"""+imgBin+"""" style="width: 100%">
                </div>
                """
    except:
        print("Error opening that file.")
        exit()
    imagefile = input("Please enter the image you would like to add (requires the full path). If complete enter Q. ")
    


filename = "output.html"


htmlbase = """
    <!DOCTYPE html>
    <html>
    <head>
    <title>Slideshow</title>
    <style type="text/css">
    body {font-family: sans-serif;}
    .mySlides {display: none;}
    img {vertical-align: middle;}

    /* Slideshow container */
    .slideshow-container {
    max-width: 100%;
    position: relative;
    margin: auto;
    }


    /* Fading animation */
    .fade {
    -webkit-animation-name: fade;
    -webkit-animation-duration: 1.5s;
    animation-name: fade;
    animation-duration: 1.5s;
    }

    @-webkit-keyframes fade {
    from {opacity: .4} 
    to {opacity: 1}
    }

    @keyframes fade {
    from {opacity: .4} 
    to {opacity: 1}
    }

    </style>
    </head>
    <body>
	<div class="slideshow-container">
    """+imginfo+"""

	</div>
    <script>
    var slideIndex = 0;
    showSlides();

    function showSlides() {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    
    for (i = 0; i < slides.length; i++) {
        slides[i].style.display = "none";  
    }
    slideIndex++;
    if (slideIndex > slides.length) {slideIndex = 1}
    slides[slideIndex-1].style.display = "block";  
    setTimeout(showSlides, """+str_delay+""");
    }
    </script>

    </body>
    </html> 

"""

try:
    outputfile = open(filename, "a")
    outputfile.write(htmlbase)

except:
    print("Error writing to that file")
    exit()
