import itertools, os, sys try: from tqdm import tqdm except: pass args = sys.argv help_mode = "help" in args file_mode = "file" in args server_mode = "server" in args path = list(filter(lambda x: x.endswith("/") or x.endswith("\\"), args)) if help_mode: print(f'Usage: python generate.py [args]') print(f'Args:') print(f'\thelp - Show this message') print(f'\tfile - File mode with .html extension') print(f'\tserver - Server mode without .html extension for use folder as static pages') print(f'\t[path]/ - Directory for save pages') exit(0) else: if file_mode and server_mode: print("args 'file' and 'server' is incompatible") exit(1) elif not (file_mode or server_mode): print("args 'file' or 'server' is required") exit(1) elif len(path) > 1: print("args must contain only one path (optional)") exit(1) if len(path) == 0: path = "static/" else: path = path[0] def check_win(board) -> str: lines = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], # rows [0, 3, 6], [1, 4, 7], [2, 5, 8], # columns [0, 4, 8], [2, 4, 6] # diagonals ] return next((board[line[0]] for line in lines if board[line[0]] == board[line[1]] == board[line[2]] != '-'), '-') minify = lambda s: s.replace('\n', '').replace('\t', '').replace(' ', '') style = minify(""" body{margin:0;padding:20px;font-family:Arial,sans-serif;text-align:center;background:#fff}h1{font-size:24px;margin-bottom:20px} a{text-decoration:none}img{width:10vw}a,h1 a{color:#007bff}table{margin:0 auto;border-collapse:collapse;max-width:100%;overflow-x:auto} td,td a{line-height:50px}td{border:1px solid #ccc;padding:10px;width:50px;height:50px;text-align:center;font-size:18px;vertical-align:middle} td a{display:block;width:100%;height:100%;color:#007bff}td:hover{background:#eee}@media (max-width:600px){body{padding:10px}img{width:20vw} h1{font-size:20px;margin-bottom:10px}td{padding:5px;width:40px;height:40px;font-size:16px}td,td a{line-height:40px}}""") apply_css = minify(f"const style=document.createElement('style');style.textContent='{style}';document.head.appendChild(style);") preload = minify(""" document.addEventListener('mouseover', e => { const a = e.target.closest('a[href]'); if (!a) return; if (!a.dataset.prefetched) { a.dataset.prefetched = true; fetch(a.href, {mode: 'no-cors'}); } }); """) pages = { 'index': minify(f"""
Select team for start [ O | X ]
{'
multiplayer mode' if server_mode else ''}
| {'' if field[1] != '-' else f''}{field[1].replace('-', '□')}{'' if field[1] != '-' else ''} | {'' if field[2] != '-' else f''}{field[2].replace('-', '□')}{'' if field[2] != '-' else ''} | {'' if field[3] != '-' else f''}{field[3].replace('-', '□')}{'' if field[3] != '-' else ''} |
| {'' if field[4] != '-' else f''}{field[4].replace('-', '□')}{'' if field[4] != '-' else ''} | {'' if field[5] != '-' else f''}{field[5].replace('-', '□')}{'' if field[5] != '-' else ''} | {'' if field[6] != '-' else f''}{field[6].replace('-', '□')}{'' if field[6] != '-' else ''} |
| {'' if field[7] != '-' else f''}{field[7].replace('-', '□')}{'' if field[7] != '-' else ''} | {'' if field[8] != '-' else f''}{field[8].replace('-', '□')}{'' if field[8] != '-' else ''} | {'' if field[9] != '-' else f''}{field[9].replace('-', '□')}{'' if field[9] != '-' else ''} |