#!/usr/bin/python3 import glob, fileinput, os, re, shutil, sys, tempfile, time year = 2022 webfile_dir = "~/public_html/GunRun{}/".format(year) print("NOTE: year is {}".format(year)) webfile_dir = os.path.expanduser(webfile_dir) for root, dirs, files in os.walk(webfile_dir): documents=[] for file in files: if re.search('.(pdf|png|jpg|jpeg|htm|html|mp4|pptx)$', file) and not re.search('index.html', file): try: documents.append(os.path.join(file)) except OSError: pass canonical=[] archive=[] marshals=[] for file in documents: name=os.path.basename(file) if re.search('^\d{8}', name): archive.append(name) elif re.search('_marshal_map_', name): marshals.append(name) else: canonical.append(name) indexfile = open(os.path.join(webfile_dir, root, "index.html"), "w") output = """ Gun Run {} Maps

Gun Run {} Maps

""".format(year, year) if canonical: output += """

Maps

""" if dirs: output +="""

Clubs

""" if archive: archive=[i.split(' - ') for i in archive] archive.sort(key=lambda line: (line[2],line[0])) archive = [' - '.join(i) for i in archive] output +="""

Source Maps

""" if marshals: output +="""

Marshal maps

""" marshals.sort(key=lambda x: int(re.sub('^.*_(\d+)\..{3,6}?$', '\g<1>', x))) positions={} for link in marshals: m = re.search('^(.*?).(pdf|png|jpg|jpeg)$', link) if m is not None: positions.setdefault(m.group(1), {})[m.group(2)] = link for name, ext in positions.items(): day = re.sub('^(\d+)_.*', '\g<1>', name) num = re.sub('(?:\d+_)\D+', '', name) if day == "1": day = "Saturday" else: day = "Sunday" output += """""" output += """""".format(day) output += """""".format(num) for link in ext.values(): output += """""".format(link, link) output += """""" output += """
{}{}{}
""" output += """""" indexfile.write(output) indexfile.close() # vim: set expandtab shiftwidth=4 softtabstop=4 :