Skip to content

Instantly share code, notes, and snippets.

@GiovanniFrigo
Created November 17, 2015 09:53
Show Gist options
  • Save GiovanniFrigo/d2c8c3b55697e563b174 to your computer and use it in GitHub Desktop.
Save GiovanniFrigo/d2c8c3b55697e563b174 to your computer and use it in GitHub Desktop.
Generate html file from images in a directory (recursive)
#!/usr/bin/python2.7
from os import listdir, makedirs, path
from shutil import copy
f = open('output.html', 'w')
def process(directory):
if not directory.endswith( '/' ):
directory += "/"
for item in listdir(directory):
if path.isfile(path.join(directory, item)):
if item.endswith('.jpg'):
f.write(' <tr>\n')
f.write(' <img src="' + path.join(directory, item) + '"/>\n')
f.write(' </tr>\n');
else:
process( path.join(directory, item) )
if __name__ == '__main__':
f.write('<!DOCTYPE html>\n')
f.write('<html>\n')
f.write(' <head>\n')
f.write(' <title>Presentazione dati</title>\n')
f.write(' </head>\n')
f.write(' <body>\n')
f.write(' <table>\n')
process('.')
f.write(' </table>\n')
f.write(' </body>\n')
f.write('</html>\n')
print ("\n------------------")
print ("Everything OK.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment