TC2-APRS-BBS/main.py
2025-04-28 22:29:56 +02:00

54 lines
2.1 KiB
Python

import database
import aprs_comm
import threading
import time
import signal
import sys
def scheduled_cleanup():
"""Periodically run cleanup of expired bulletins."""
while True:
try:
print("Running periodic cleanup of expired bulletins...")
database.delete_expired_bulletins()
except Exception as e:
print(f"Error during cleanup: {e}")
time.sleep(24 * 60 * 60) # Run cleanup every 24 hours
def signal_handler(signum, frame):
print(f"Received signal {signum}. Shutting down...")
aprs_comm.shutdown()
def main():
banner = """
\033[96m
████████╗ ██████╗██████╗ ██████╗ ██████╗ ███████╗
╚══██╔══╝██╔════╝╚════██╗ ██╔══██╗██╔══██╗██╔════╝
██║ ██║ █████╔╝█████╗██████╔╝██████╔╝███████╗
██║ ██║ ██╔═══╝ ╚════╝██╔══██╗██╔══██╗╚════██║
██║ ╚██████╗███████╗ ██████╔╝██████╔╝███████║
╚═╝ ╚═════╝╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝
\033[93mAPRS Version\033[0m
"""
print(banner)
print("Initializing database...")
database.init_db()
# Start periodic bulletin cleanup in a separate thread
cleanup_thread = threading.Thread(target=scheduled_cleanup, daemon=True)
cleanup_thread.start()
print("Setting up signal handlers...")
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
signal.signal(signal.SIGTERM, signal_handler) # kill command
print("Starting APRS communications...")
aprs_comm.start()
return 0
if __name__ == "__main__":
main()