User:Inductiveload/Scripts/Index page tabulator
Appearance
This script will output a text file containing the wiki markup for the table. For an example of its use, see Index:The Complete Collection of Pictures & Songs by Randolph Caldecott.jpg.
Source code
[edit]#!/usr/bin/python
'''
create a table of pages from images for use in index pages.
'''
# Filenames: PREFIX + DIGITS + SUFFIX + EXT
PREFIX = "Randolph_Caldecott_collection-page_"
SUFFIX = ""
EXT = ".jpg"
DIGITS = 4 #length of the numeric components
NUMBER = 199 # number of pages in total
STARTAT = 1 # first page number
ROWLENGTH=10 # number of pages in a row of the table
TITLE = "The Complete Collection of Pictures & Songs by Randolph Caldecott" #title of the table
OUTFILE = r'c:\temp2.txt' #where the table will be written to.
outfile= open(OUTFILE, 'w')
precstr = "%0" + str(DIGITS) + "d"
newline = "{| cellspacing=2 cellpadding=4 border=0 |\n"
newline += "|+\n"
newline += '|colspan=10 align=center style="border-top: 2px solid #808080; background-color: #f4f0e5;"|'+"'''" + TITLE + "'''\n"
outfile.write(newline)
outfile.flush()
for i in range( int(round(NUMBER//ROWLENGTH + 0.5)) ):
newline = "|-\n"
for j in range(ROWLENGTH):
index = i*ROWLENGTH + j + STARTAT
newline += "|bgcolor=#F0F0F0 align=center|"
if index <= NUMBER:
newline += "[[Page:" + PREFIX + precstr%index + SUFFIX + EXT + "|" + str(index) + "]]\n"
else:
newline += ' \n'
outfile.write(newline)
outfile.flush()
outfile.write("|}\n")
outfile.flush()