From c9639d851b91bb64046b18b5c5c2ed215f534706 Mon Sep 17 00:00:00 2001 From: pablorevilla-meshtastic Date: Thu, 15 Jan 2026 08:48:22 -0800 Subject: [PATCH] Fix Time function on store.py --- README.md | 32 ++++++++++++++++++++++++++++---- meshview/store.py | 12 ++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 798d58e..e4c8535 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,18 @@ password = large4cats # postgresql+asyncpg://user:pass@host:5432/meshview connection_string = sqlite+aiosqlite:///packets.db +> **NOTE (PostgreSQL setup)** +> If you want to use PostgreSQL instead of SQLite: +> +> 1) Install PostgreSQL for your OS. +> 2) Create a user and database: +> - `CREATE USER meshview WITH PASSWORD 'change_me';` +> - `CREATE DATABASE meshview OWNER meshview;` +> 3) Update `config.ini`: +> - `connection_string = postgresql+asyncpg://meshview:change_me@localhost:5432/meshview` +> 4) Initialize the schema: +> - `./env/bin/python startdb.py` + # ------------------------- # Database Cleanup Configuration @@ -496,10 +508,22 @@ sleep 5 echo "Run cleanup..." # Run cleanup queries sqlite3 "$DB_FILE" < int: try: async with database.async_session() as session: - now_us = int(datetime.now(datetime.UTC).timestamp() * 1_000_000) + now_us = int(datetime.now(timezone.utc).timestamp() * 1_000_000) cutoff_us = now_us - 86400 * 1_000_000 q = select(func.count(Node.id)).where(Node.last_seen_us > cutoff_us) @@ -196,7 +196,7 @@ async def get_total_node_count(channel: str = None) -> int: async def get_top_traffic_nodes(): try: async with database.async_session() as session: - now_us = int(datetime.now(datetime.UTC).timestamp() * 1_000_000) + now_us = int(datetime.now(timezone.utc).timestamp() * 1_000_000) cutoff_us = now_us - 86400 * 1_000_000 total_packets_sent = func.count(func.distinct(Packet.id)).label("total_packets_sent") total_times_seen = func.count(PacketSeen.packet_id).label("total_times_seen") @@ -244,7 +244,7 @@ async def get_top_traffic_nodes(): async def get_node_traffic(node_id: int): try: async with database.async_session() as session: - now_us = int(datetime.now(datetime.UTC).timestamp() * 1_000_000) + now_us = int(datetime.now(timezone.utc).timestamp() * 1_000_000) cutoff_us = now_us - 86400 * 1_000_000 packet_count = func.count().label("packet_count") @@ -309,7 +309,7 @@ async def get_nodes(node_id=None, role=None, channel=None, hw_model=None, days_a query = query.where(Node.hw_model == hw_model) if days_active is not None: - now_us = int(datetime.now(datetime.UTC).timestamp() * 1_000_000) + now_us = int(datetime.now(timezone.utc).timestamp() * 1_000_000) cutoff_us = now_us - int(timedelta(days_active).total_seconds() * 1_000_000) query = query.where(Node.last_seen_us > cutoff_us) @@ -337,7 +337,7 @@ async def get_packet_stats( to_node: int | None = None, from_node: int | None = None, ): - now = datetime.now(datetime.UTC) + now = datetime.now(timezone.utc) if period_type == "hour": start_time = now - timedelta(hours=length)