import os
import numpy as np
from datetime import datetime, timedelta
##########################################################################
#########################疑似データ生成用
##########################################################################



# 列名
columns = ["数学", "理科", "国語", "社会", "英語"]

def create_html_file(file_path, current_date):
    # ランダムな単語の生成
    random_words = np.random.choice(["萬子1", "萬子2", "萬子3", "萬子4", "萬子5", "萬子6", "萬子7", "萬子8", "萬子9",
                 "筒子1", "筒子2", "筒子3", "筒子4", "筒子5", "筒子6", "筒子7", "筒子8", "筒子9",
                 "索子1", "索子2", "索子3", "索子4", "索子5", "索子6", "索子7", "索子8", "索子9",
                 "東", "南", "西", "北", "白", "発", "中"], size=(5, len(columns)))

    # HTMLコンテンツの作成
    html_content = f"""
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Generated HTML</title>
    </head>
    <body>
        <h1>Table for {current_date}</h1>
        <table border="1">
            <tr>
                <th>{columns[0]}</th>
                <th>{columns[1]}</th>
                <th>{columns[2]}</th>
                <th>{columns[3]}</th>
                <th>{columns[4]}</th>
            </tr>
    """

    # ランダムな単語で表を埋める
    for row in random_words:
        html_content += "<tr>"
        for cell in row:
            html_content += f"<td>{cell}</td>"
        html_content += "</tr>"

    html_content += """
        </table>
    </body>
    </html>
    """

    # HTMLファイルの保存（UTF-8で書き込み）
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(html_content)

def generate_html_files(start_date, end_date, base_folder='data'):
    current_date = start_date
    while current_date <= end_date:
        # フォルダの作成
        folder_path = os.path.join(base_folder, current_date.strftime('%Y/%m'))
        os.makedirs(folder_path, exist_ok=True)

        # ファイルパスの作成
        file_path = os.path.join(folder_path, f"{current_date.strftime('%d')}.html")

        # HTMLファイルの作成
        create_html_file(file_path, current_date.strftime('%Y-%m-%d'))

        # 次の日に進む
        current_date += timedelta(days=1)

if __name__ == "__main__":
    start_date = datetime(2020, 1, 1)
    end_date = datetime(2024, 1, 1)

    generate_html_files(start_date, end_date)

    print("HTML files generated successfully.")
