# Densuke Schedule Viewer

This is a web application that fetches, parses, and displays schedule data from a specified densuke.biz URL. It provides a clean, transposed view of the schedule, filtered by date.

## Features

- Fetches schedule data from a public densuke.biz page.
- Filters the schedule by a user-selected date.
- Transposes the table for better readability (members as rows).
- Filters out members who are unavailable ('×').
- Sorts members to show participants ('○') before tentative participants ('△').

## Project Structure

- `frontend/`: Contains the static frontend files (HTML, CSS, JavaScript).
- `backend/`: Contains the Flask backend application, which serves the frontend and provides the `/api` endpoint.

## Setup and Installation

### 1. Clone the repository

```bash
git clone <repository-url>
cd <repository-directory>
```

### 2. Set up the Backend

First, install the Python dependencies:

```bash
pip install -r backend/requirements.txt
```

### 3. Configure Environment Variables

Create a `.env` file in the project root directory by copying the example file:

```bash
cp .env.example .env
```

Modify the `.env` file to set the desired port for the backend server.

```
# .env
PORT=8000
```

## Running the Application

### Development

You can run the Flask development server directly:

```bash
python backend/main.py
```

The application will be available at `http://localhost:8000`.

### Production with Gunicorn

For a production environment, it is recommended to use a WSGI server like Gunicorn.

To start the backend server with Gunicorn, run the following command from the project's root directory:

```bash
gunicorn --bind 0.0.0.0:8000 --chdir backend wsgi:app
```

Replace `8000` with the port you configured in your `.env` file if it's different.

## Apache Reverse Proxy Configuration

To deploy this application behind an Apache web server, you can use a reverse proxy configuration. This allows Apache to handle incoming HTTPS and static file requests, while forwarding API requests to the Gunicorn backend.

Here is an example Apache Virtual Host configuration:

```apache
<VirtualHost *:80>
    ServerName yourdomain.com
    ServerAdmin webmaster@yourdomain.com
    DocumentRoot /path/to/your/project/frontend

    # Proxy API requests to the Gunicorn backend
    ProxyPreserveHost On
    ProxyPass /api http://127.0.0.1:8000/api
    ProxyPassReverse /api http://127.0.0.1:8000/api

    # Serve static files from the frontend directory
    <Directory /path/to/your/project/frontend>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```

**Notes:**

1.  Replace `yourdomain.com` with your actual domain name.
2.  Replace `/path/to/your/project/frontend` with the absolute path to the `frontend` directory.
3.  Ensure that Apache's proxy modules (`mod_proxy` and `mod_proxy_http`) are enabled:
    ```bash
    sudo a2enmod proxy
    sudo a2enmod proxy_http
    sudo systemctl restart apache2
    ```
4.  The `DocumentRoot` should point to the `frontend` directory to allow Apache to serve the static files directly. Requests for `/api` will be forwarded to the backend Gunicorn server running on port `8000`.
