# -*- coding: utf-8 -*- # Copyright Brett Paufler 7-12-13 #SPORADIC WILL NEED TO TOUCH UP MANUALLY #SPORADIC - No Warranty - As IS #Complain after you've paid me a six digit licensing fee #This is a Python Program #PYTHON 2.75 is required to run # Ending comma in JSON file will need to be trimmed # will capture all files in dictory, so trimming of JSON is expected #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 = """./""" # replace above """ with below, to dynamically change directory #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 #(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() F2 = open('ThirdText.txt', 'w+') for line in fileinput.input('SecondTemp.txt'): F2.write('{"Title" : "') F2.write(line[:line.find('-') - 1] + '", \n') F2.write('"alt" : "') F2.write(line) F2.write('"src" : "' + PictureDirectory) line = line.replace(' ', '%20') F2.write(line) F2.write('"TextOne" : "", \n') F2.write('"TextTwo" : "", \n') F2.write('"TextThree" : "" \n') #F2.write('"Title" : "", \n') F2.write('}, \n\n') #titleCaption = item[:item.find('-') - 1] #print titleCaption F2.close() # if this file is Temp changed to txt, editing/trouble shooting is way easier F3 = open('00 - JSON Image Object.txt', 'w+') F3.write('var imageObjectJSON = [') # 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') #F3.write('\n\n\n\n
\n\n
\n\n
\n') # Final Image src output for line in fileinput.input('ThirdText.txt'): #F3.write('\n') #F3.write("""{""") F3.write(line) # End of File write area, add or delete as needed, for buttons, etc F3.write(""" //This Page Created By BrettFood's JSON Image Object Creator //Copyright Brett Paufler 2013 """) #PageEndingText = """ #
# #""" #F3.write(PageEndingText) F3.close() os.remove('TempText.txt') os.remove('SecondTemp.txt') os.remove('ThirdText.txt')