import sqlite3
from datetime import datetime
from typing import List, Tuple


def fetch_logs() -> List[Tuple[int, str]]:
    conn = sqlite3.connect("activity_log.db")
    cursor = conn.cursor()
    cursor.execute("SELECT id, timestamp FROM activity_log ORDER BY id ASC")
    logs = cursor.fetchall()
    conn.close()
    return logs


def filter_logs_by_hour(logs: List[Tuple[int, str]]) -> List[Tuple[int, str]]:
    filtered_logs = []
    last_log_time = None
    for log_id, timestamp in logs:
        log_time = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
        if last_log_time is None or (log_time - last_log_time).seconds >= 3600:
            filtered_logs.append((log_id, timestamp))
            last_log_time = log_time
    return filtered_logs


def display_logs() -> None:
    logs = fetch_logs()
    if not logs:
        print("No logs found.")
        return
    filtered_logs = filter_logs_by_hour(logs)
    for log_id, timestamp in filtered_logs:
        print(f"ID: {log_id}, Timestamp: {timestamp}")


if __name__ == "__main__":
    display_logs()
