I made a nice gallery full of photographs of all the books currently on my bookshelf. In the next few months I’ll be getting rid of all of them, and it will be tough to let go of some. So this is for the memories.
By the way, I finally figured out the lightbox gallery that I was moaning about in a previous post, many months ago. I’m using it to display the pictures all nice and fancy. But there are almost a hundred of them, and that makes for some tedious html and xml coding. Fortunately, with all the education I’ve recently acquired, it was a little easier. I used a PHP script to grab the filenames of the pictures, thumbnail versions, author name and title of the books out of an xml file and spit it out in html.
The tough part was the xml file. The finished product was over a thousand lines long and I’m not typing that crap.
First, put all the thumbnails in one folder with names like booktitle-t.jpg. The large versions go in another folder with names like booktitle.jpg. Go like this…
1 2 |
ls >list_thumbnails.txt ls >list_pictures.txt |
…from the command line to get lists of all the file names.
Then use this quick python script to add the xml tags.
1 2 3 4 5 6 7 8 9 10 11 12 |
picfile = open("list_pictures2.txt") //always make a backup while(1): firstline = picfile.readline(); if not firstline: break pass //here's the meaty bit xmlnode = "<pathToPic>\n\t\timages/" + firstline + "\t</pathToPic>\n" print xmlnode picfile.close() //close the file when you're don |
so that gets you this:
1 2 3 |
<pathToPic> images/booktitle.jpg </pathToPic> |
Awesome. Add lines for the thumbnails, author and title as well.
1 2 |
picfile = open("list_pictures2.txt") thumbfile = open("thumbs/list_thumbs2.txt") |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
while(1): firstline = picfile.readline(); secondline = thumbfile.readline(); if not firstline: break pass xmlnode = "<book>\n\t<pathToPic>\n\t\timages/" + firstline + "\t</pathToPic>\n\t<pathToThumb>\n\t\timages/thumbs/" + secondline + "\t</pathToThumb>\n\t<title>\n\n\t</title>\n\t<author>\n\n\t</author>\n</book>" print xmlnode picfile.close() thumbfile.close() |
Which gets you this:
1 2 3 4 5 6 7 8 |
<book> <pathToPic> images/booktitle.jpg </pathToPic> <pathToThumb> images/thumbs/booktitle-t.jpg </pathToThumb> <author> |
1 2 |
</author> <title> |
1 2 |
</title> </book> |
Then just add the Author and Title fields by hand, unless you have a better idea. Run it like so:
1 |
python script.py >booklist.xml |
I suppose there’s a proper way to write to a text file from within the script, but I never got around to looking that up.