Advertisement
firebfm

createhtml.py

Dec 25th, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import os
  2. from pathlib import Path
  3.  
  4. newlistjpeg = []
  5. htmlstring2 = ""
  6.  
  7. path = input('Enter path of images folder to create html\n')
  8. parentpath = Path(path).parent
  9.  
  10. listjpeg = [os.path.join(path, f) for f in os.listdir(path) if f.lower().endswith(('.jpg', '.jpeg'))]
  11. htmlstring1 = f'''
  12. <!DOCTYPE html>
  13. <html>
  14. <head>
  15. <title>My Images</title>
  16. </head>
  17. <body>
  18. <div id="my-images">'''
  19.  
  20. for img in listjpeg:
  21. img = img.replace("\\", "/")
  22. img = "%20".join(img.split())
  23. newlistjpeg.append(img)
  24.  
  25. listlength = len(newlistjpeg)
  26.  
  27. for i in range(0, listlength):
  28. htmlstring2 += f'''
  29. <img src="file://{newlistjpeg[i]}" />'''
  30.  
  31. htmlstring3 = f'''
  32. </div>
  33. </body>
  34. </html>'''
  35.  
  36. fullhtml = htmlstring1 + htmlstring2 + htmlstring3
  37.  
  38. with open(os.path.join(parentpath, "index.html"), "w", encoding='utf8') as writefile:
  39. writefile.write(fullhtml)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement