''' Created on Sep 5, 2013 CopyRight Brett Paufler HTML Page Creator with CSS for Figure & Captions ''' # -*- coding: utf-8 -*- # Copyright Brett Paufler 7-12-13 #Place this program in File Location where HTML page is desired # Programe creates HTML file with image src based on relative path # Alternative (alt=) value is set to file name # Spaces are converted %20 # Any other special Characters (brackets, commas, etc) # will (likely)result in garbage import os import fileinput # Default variables for Name, Title, etc # Change these, comment out the raw_input lines below # and having to type in your name each time will be eliminated PageTitle = 'Brett Food - Brett Paufler\'s Guide to Cooking' PageAuthor = 'Brett Paufler' #Input Output area for user defined varialbes #Easy enough to comment out #PageTitle = raw_input("Desired Page Title: ") #PageAuthor = raw_input("Page Author (for Meta Tag):") PictureDirectory = raw_input(""" Path To Pictures Enter a Period (single dot: ./ )if in Same Directory (./) If in sub folder named Images Enter: Images/ (Ending Forwardk Slash "/" is required) I use this 2 layers deep, other conditions not tested ',' Commas in file names will mess things up NOTE: This is the figure figcaption version (images/ThisImageFile/ works for me) ENTER THE RELATIVE PATH TO THE PICTURES (with ending forward /) """) #Get DirectoryList String DirectoryList = os.listdir(PictureDirectory) DirectoryList = str(DirectoryList) # Opens and closed various files which are subsequently removed to # caconate the Directory List string correctly IsOpen = open('TempText.txt', 'w+') IsOpen.write(DirectoryList) IsOpen.close() #images/ F1 = open('SecondTemp.txt', 'w+') for line in fileinput.input('TempText.txt'): line = line.replace(', ', '\"\n') line = line.replace('\'', '') line = line.replace('[', '') line = line.replace(']', '\"\n') F1.write(line) F1.close() captionCount = 1 F2 = open('ThirdText.txt', 'w+') for line in fileinput.input('SecondTemp.txt'): #F2.write(' F2.write('
\"')') F2.write('
' + str(captionCount) + 'Caption Goes Here
\n') captionCount += 1 F2.write('
\n\n\n\n') F2.close() # if this file is Temp changed to txt, editing/trouble shooting is way easier F3 = open('Z - BrettFoodWebPageCreator.html', 'w+') # Head of File write area F3.write('\n\n\n\n\n\n') F3.write('\n\n') F3.write('' + PageTitle + ' \n\n') F3.write('\n\n') inLineCssCode = """""" F3.write(inLineCssCode) F3.write('\n\n\n\n
\n\n
\n\n
\n') # Final Image src output for line in fileinput.input('ThirdText.txt'): F3.write(line) # End of File write area, add or delete as needed, for buttons, etc F3.write(""" This Page Created By BrettFood's Image Loader HTML Page Creator FigCaption Version 2.0 Copyright 2013 Brett Paufler \n\n

\n\n """) PageEndingText = """
""" F3.write(PageEndingText) F3.close() os.remove('TempText.txt') os.remove('SecondTemp.txt') os.remove('ThirdText.txt')