Background: I am looking to create a HTML file that maps html pages to images within a directory. There are two specific formats for how the article lines are written. One if an article is linked to a jpg(s) and two if no html article is linked to an image.
Sample scenario: I have 12 html files & 56 full page images (jpg). Within the 12 html files, 32 page images are associated to the text. The remaining page images are not related to the text but must be included in the output file. I am trying to list the html file names and ask the user which numbered jpgs are linked to the html file.
The output that I am looking to end up with is something similar to the following:
<Item="1" img="/pg-01.jpg" />
<Item="2" img="/pg-02.jpg" ><Link="text_1.html"></Link></Item>
<Item="3" img="/pg-03.jpg" ><Link="text_1.xml"></Link></Item>
<Item="4" img="/pg-04.jpg" ><Link="text_2.html"></Link></Item>
<Item="5" img="/pg-05.jpg" ><Link="text_2.html"></Link></Item>
<Item="6" img="/pg-06.jpg" />
<Item="7" img="/pg-07.jpg" ><Link="text_3.html"></Link></Item>
<Item="8" img="/pg-08.jpg" />
<Item="9" img="/pg-09.jpg" ><Link="text_3.html"></Link></Item>
This is the current code I have which lists the images correctly, however I cannot figure out how to also ask the user for values linked to the html when I am asking for the name.
import sys
import os.path
import zipfile
import glob
contents = raw_input("Choose a filename for your zip:")
zip = zipfile.ZipFile(contents + ".zip", 'w')
html_assets = glob.glob('./*.xml')
image_assets = glob.glob('./pg*.jpg' )
map_tpl = '''
<Title>%(title)s</Title>
<Articles>
%(articles)s
</Articles>
<filename>
%(filename)s
</filename>'''
articles = ""
filename = ""
title = raw_input("What is the title of the HTML file ?")
for i, html in enumerate(html_assets):
basename = os.path.basename(html)
filename += '<filename="%s" file="%s"> <title>%s</title> </filename>' % (
basename, basename,raw_input('What is the html name for ' + basename))
for i, jpg in enumerate(image_assets):
basename = os.path.basename(jpg)
articles += '<Item"%s"' % (i) + ' img="/pages/%s"' % ( basename
)
zip.writestr('/map.html', map_tpl % {
'title': title,
'articles': articles,
'filename': filename
})
I think it would work best if the prompts looked something like this:
What is the title of the HTML file ? (user input) What is the article name for text_1.html (user input) Which images are linked text_1.html (02,03) <--- user input What is the article name for text_2.html (user input) Which images are linked text_2.html (04,05) <--- user input What is the article name for text_3.html (user input) Which images are linked text_3.html (07,09) <--- user input etc
(Note all values which are not entered by the user are rendered like Item1 in the example
I have spent the last few days trying to tackle this and any assistance anyone can provide is greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire