import os import os.path import time version = "1.1" header = ( "" "" "" "" "Index of {}" "" "" "" "" "" "" "
" "

Index of {}

" "" "
" "" "" "" "" "" "" "" "" "" "" ) footer = ( "" "
NameSizeLast Modified
" "" "" "" ).format(version) icon_mapping = { ".txt": "https://cstatic.yeahgames.net/services/indexing/icons/text.svg", ".pdf": "https://cstatic.yeahgames.net/services/indexing/icons/pdf.svg", ".doc": "https://cstatic.yeahgames.net/services/indexing/icons/file/doc.svg", ".docx": "https://cstatic.yeahgames.net/services/indexing/icons/file/docx.svg", ".xls": "https://cstatic.yeahgames.net/services/indexing/icons/file/xls.svg", ".xlsx": "https://cstatic.yeahgames.net/services/indexing/icons/file/xlsx.svg", ".ppt": "https://cstatic.yeahgames.net/services/indexing/icons/file/ppt.svg", ".pptx": "https://cstatic.yeahgames.net/services/indexing/icons/file/pptx.svg", ".png": "https://cstatic.yeahgames.net/services/indexing/icons/image.svg", ".jpg": "https://cstatic.yeahgames.net/services/indexing/icons/image.svg", ".jpeg": "https://cstatic.yeahgames.net/services/indexing/icons/image.svg", ".gif": "https://cstatic.yeahgames.net/services/indexing/icons/image.svg", ".zip": "https://cstatic.yeahgames.net/services/indexing/icons/archive.svg", ".rar": "https://cstatic.yeahgames.net/services/indexing/icons/archive.svg", ".md": "https://cstatic.yeahgames.net/services/indexing/icons/markdown.svg", ".markdown": "https://cstatic.yeahgames.net/services/indexing/icons/markdown.svg", ".html": "https://cstatic.yeahgames.net/services/indexing/icons/html.svg", ".htm": "https://cstatic.yeahgames.net/services/indexing/icons/html.svg", ".py": "https://cstatic.yeahgames.net/services/indexing/icons/python.svg", ".js": "https://cstatic.yeahgames.net/services/indexing/icons/js.svg", ".css": "https://cstatic.yeahgames.net/services/indexing/icons/css.svg", ".gitignore": "https://cstatic.yeahgames.net/services/indexing/icons/file/gitignore.svg", ".svg": "https://cstatic.yeahgames.net/services/indexing/icons/file/svg.svg", ".yml": "https://cstatic.yeahgames.net/services/indexing/icons/yaml.svg", ".yaml": "https://cstatic.yeahgames.net/services/indexing/icons/yaml.svg", ".php": "https://cstatic.yeahgames.net/services/indexing/icons/php.svg", ".php": "https://cstatic.yeahgames.net/services/indexing/icons/php.svg", ".json": "https://cstatic.yeahgames.net/services/indexing/icons/json.svg", ".java": "https://cstatic.yeahgames.net/services/indexing/icons/java.svg", ".json": "https://cstatic.yeahgames.net/services/indexing/icons/json.svg", ".psd": "https://cstatic.yeahgames.net/services/indexing/icons/file/psd.svg", ".rb": "https://cstatic.yeahgames.net/services/indexing/icons/ruby.svg", ".ts": "https://cstatic.yeahgames.net/services/indexing/icons/typescript.svg", ".webp": "https://cstatic.yeahgames.net/services/indexing/icons/file/webp.svg", ".xml": "https://cstatic.yeahgames.net/services/indexing/icons/xml.svg", ".lock": "https://cstatic.yeahgames.net/services/indexing/icons/lock.svg", ".sass": "https://cstatic.yeahgames.net/services/indexing/icons/sass.svg", ".scss": "https://cstatic.yeahgames.net/services/indexing/icons/scss.svg", ".vue": "https://cstatic.yeahgames.net/services/indexing/icons/vue.svg", ".yg": "https://cstatic.yeahgames.net/services/indexing/icons/yg.svg", ".woff": "https://cstatic.yeahgames.net/services/indexing/icons/woff.svg", ".mp3": "https://cstatic.yeahgames.net/services/indexing/icons/audio.svg", ".mp4": "https://cstatic.yeahgames.net/services/indexing/icons/video.svg", ".mov": "https://cstatic.yeahgames.net/services/indexing/icons/video.svg", ".gemspec": "https://cstatic.yeahgames.net/services/indexing/icons/ruby.svg", } def convert_size(size): units = ["bytes", "KB", "MB", "GB", "TB"] unit_index = 0 while size >= 1024 and unit_index < len(units) - 1: size /= 1024 unit_index += 1 return f"{size:.1f} {units[unit_index]}" def get_icon(file_extension, is_directory): if is_directory: return "https://cstatic.yeahgames.net/services/indexing/icons/folder.svg" else: return icon_mapping.get(file_extension.lower(), "https://cstatic.yeahgames.net/services/indexing/icons/blank.svg") def getlink(path, file, isDir): file_extension = os.path.splitext(file)[1] icon = get_icon(file_extension, isDir) if isDir: return ( "" "{}/" "{}" "{}" "" "" "" "" "Size: {}
" "Last Modified: {}" "" "" ).format(icon, file, file, "-", "-", "-", "-") else: fileLen = len(file) filesz = os.path.getsize(path + "/" + file) filesz = convert_size(filesz) mtime = os.path.getmtime(path + "/" + file) mtime = time.strftime('%d-%b-%Y %H:%M', time.localtime(mtime)) return ( "" "{}" "{}" "{}" "" "" "" "" "" "" "Size: {}
" "Last Modified: {}" "" "" ).format(icon, file, file, filesz, mtime, filesz, mtime) def listfiles(path): displaypath = path if path == ".": displaypath = "/" elif displaypath.startswith("./"): displaypath = displaypath[1:] idx = open(path + "/index.html", "w") # Write the header idx.write(header.format(displaypath, displaypath)) # Write back link idx.write("..") # Write directories first for file in sorted(os.listdir(path)): if os.path.isdir(path + "/" + file): idx.write(getlink(path, file, True)) listfiles(path + "/" + file) # ... then write files for file in sorted(os.listdir(path)): if not os.path.isdir(path + "/" + file): if file.endswith("index.html"): continue idx.write(getlink(path, file, False)) idx.write(footer) idx.close() def main(): listfiles(".") if __name__ == "__main__": main()