From 0b8c64454e0bad3abc53caf2c1e4e3cd33118901 Mon Sep 17 00:00:00 2001 From: quoije Date: Mon, 1 Apr 2024 11:37:13 -0400 Subject: [PATCH] add raw to tsv, mangodb first commit, restructure --- app.py | 12 ++++++------ app_account.py => modules/app_account.py | 0 app_car.py => modules/app_car.py | 0 app_dash.py => modules/app_dash.py | 0 modules/app_db.py | 23 +++++++++++++++++++++++ app_events.py => modules/app_events.py | 0 app_gps.py => modules/app_gps.py | 0 app_obd.py => modules/app_obd.py | 0 modules/app_tsv.py | 0 modules/creds.env | 7 +++++++ modules/db_notes.tsv | 4 ++++ requirements.txt | 4 +++- 12 files changed, 43 insertions(+), 7 deletions(-) rename app_account.py => modules/app_account.py (100%) rename app_car.py => modules/app_car.py (100%) rename app_dash.py => modules/app_dash.py (100%) create mode 100644 modules/app_db.py rename app_events.py => modules/app_events.py (100%) rename app_gps.py => modules/app_gps.py (100%) rename app_obd.py => modules/app_obd.py (100%) create mode 100644 modules/app_tsv.py create mode 100644 modules/creds.env create mode 100644 modules/db_notes.tsv diff --git a/app.py b/app.py index 4e174ee..8021526 100644 --- a/app.py +++ b/app.py @@ -1,15 +1,15 @@ from flask import Flask, render_template, make_response, json -import app_obd, app_car, app_account, app_gps, time -from app_events import socketio +import modules.app_obd, modules.app_car, modules.app_account, modules.app_gps, time +from modules.app_events import socketio from gevent.pywsgi import WSGIServer app = Flask(__name__) socketio.init_app(app) -account = app_account.Account() -obd = app_obd.OBD() -car = app_car.Car() -gps = app_gps.get_gps() +account = modules.app_account.Account() +obd = modules.app_obd.OBD() +car = modules.app_car.Car() +gps = modules.app_gps.get_gps() @app.route('/') def index(): diff --git a/app_account.py b/modules/app_account.py similarity index 100% rename from app_account.py rename to modules/app_account.py diff --git a/app_car.py b/modules/app_car.py similarity index 100% rename from app_car.py rename to modules/app_car.py diff --git a/app_dash.py b/modules/app_dash.py similarity index 100% rename from app_dash.py rename to modules/app_dash.py diff --git a/modules/app_db.py b/modules/app_db.py new file mode 100644 index 0000000..55ae9ef --- /dev/null +++ b/modules/app_db.py @@ -0,0 +1,23 @@ +from pymongo import MongoClient +from dotenv import load_dotenv +import os + +load_dotenv("./creds.env") + +mUser = os.getenv() +mPass = os.getenv() +mDB = os.getenv() + +def get_database(): + + # 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) + +# This is added so that many files can reuse the function get_database() +if __name__ == "__main__": + + # Get the database + dbname = get_database() \ No newline at end of file diff --git a/app_events.py b/modules/app_events.py similarity index 100% rename from app_events.py rename to modules/app_events.py diff --git a/app_gps.py b/modules/app_gps.py similarity index 100% rename from app_gps.py rename to modules/app_gps.py diff --git a/app_obd.py b/modules/app_obd.py similarity index 100% rename from app_obd.py rename to modules/app_obd.py diff --git a/modules/app_tsv.py b/modules/app_tsv.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/creds.env b/modules/creds.env new file mode 100644 index 0000000..a1b6dd0 --- /dev/null +++ b/modules/creds.env @@ -0,0 +1,7 @@ +## +## MangoDB server connection details +## + +mangosrv_user = "" +mangosrv_pass = "" +mangosrv_db = "" \ No newline at end of file diff --git a/modules/db_notes.tsv b/modules/db_notes.tsv new file mode 100644 index 0000000..0fe5e1c --- /dev/null +++ b/modules/db_notes.tsv @@ -0,0 +1,4 @@ +## TSV File to MangoDB +## VN_20240401_00_00_00.TSV +## +## VN NAME, DATE, TIME, GPS_X, GPS_Y, SPEED, ODOMETER \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7ec2998..5563dd8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Flask Flask-SocketIO -gevent \ No newline at end of file +gevent +pymongo +python-dotenv \ No newline at end of file