Squashed rewrite of the project revival work (replaces prior history on this branch to remove personal data that had been accidentally committed - real LAN IP, GPS coordinates, home WiFi SSID, and phone model). See PLAN.md for full phase-by-phase details. Summary: - Phase 2: adapt app_obd.py for a USB OBD-II adapter (was Bluetooth-only), auto-detect /dev/ttyUSB*, fix several pre-existing crash bugs. - Phase 3/4: make the web UI work fully offline (vendored Socket.IO/Leaflet/ Chart.js/FontAwesome, offline map tile downloader script, live GPS marker tracking fix). - Phase 5: systemd deployment/autostart on the Pi. - Phase 6: WiFi hotspot mode via NetworkManager (auto-switch between home WiFi and a local AP for in-car web UI access), mDNS hostname + port 80 redirect so the UI is reachable at a plain hostname with no port number. - Phase 7: fix app_db.py/app_sql.py bugs, wire up local SQLite trip logging. - Phase 8: brand-agnostic USB dashcam file retrieval (lsblk transport-based detection, works with any dashcam brand/folder layout). - Rewritten readme.md with a proper project overview. Co-authored-by: Copilot <[email protected]>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from pymongo import MongoClient
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
# Load creds.env from the repo's db/ folder regardless of the process's cwd.
|
|
_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
load_dotenv(os.path.join(_BASE_DIR, "db", "creds.env"))
|
|
|
|
mUser = os.getenv("mangosrv_user")
|
|
mPass = os.getenv("mangosrv_pass")
|
|
mDB = os.getenv("mangosrv_db")
|
|
|
|
def get_database():
|
|
if not mUser or not mPass or not mDB:
|
|
raise RuntimeError(
|
|
"MongoDB credentials are missing. Set mangosrv_user, mangosrv_pass, "
|
|
"and mangosrv_db in db/creds.env."
|
|
)
|
|
|
|
# Provide the mongodb atlas url to connect python to mongodb using pymongo
|
|
CONNECTION_STRING = "mongodb+srv://" + mUser + ":" + mPass + "@cluster.mongodb.net/" + mDB
|
|
|
|
# Create a connection using MongoClient. You can import MongoClient or use pymongo.MongoClient
|
|
client = MongoClient(CONNECTION_STRING)
|
|
return client[mDB]
|
|
|
|
# This is added so that many files can reuse the function get_database()
|
|
if __name__ == "__main__":
|
|
|
|
# Get the database
|
|
dbname = get_database() |