Commit c4ca5413 by arun.uday

commit3

parent 7583b00c
import uvicorn
from scripts.config.application_config import uvicorn_host, uvicorn_port
from scripts.config.application_config import uvicorn_host, uvicorn_port, uvicorn_app
# starting the application
if __name__ == "__main__":
print("Fast API task")
uvicorn.run("scripts.services.receiver_app_services_run:app", host=uvicorn_host, port=int(uvicorn_port))
print("MQTT task")
uvicorn.run(uvicorn_app, host=uvicorn_host, port=int(uvicorn_port))
......@@ -15,3 +15,11 @@ requests = 60
[uvicorn]
uvicorn_host = 127.0.0.1
uvicorn_port = 8001
uvicorn_app = scripts.services.receiver_app_services_run:app
[db]
db_name = user_details.db
db_table = details
[encode]
encode = utf-8
\ No newline at end of file
......@@ -20,9 +20,17 @@ request_no = config.get("mqtt", "requests")
# uvicorn
uvicorn_host = config.get("uvicorn", "uvicorn_host")
uvicorn_port = config.get("uvicorn", "uvicorn_port")
uvicorn_app = config.get("uvicorn", "uvicorn_app")
# file name
file_name_csv = config.get("file", "file_name_csv")
file_name_json = config.get("file", "file_name_json")
full_path_csv = base_path + sub_path + file_name_csv
full_path_json = base_path + sub_path + file_name_json
# db name
db_name = config.get("db", "db_name")
db_table = config.get("db", "db_table")
# encode
utf_encode = config.get("encode", "encode")
import sqlite3
from scripts.config.application_config import db_name, db_table
from scripts.utilis.db_queries import DbQueries
class SqliteOperations:
def __init__(self):
# connecting to the database
self.conn = sqlite3.connect('user_details.db')
self.conn = sqlite3.connect(db_name)
def create_db(self):
try:
# creating the table
self.conn.execute('''CREATE TABLE IF NOT EXISTS details
(ID INT PRIMARY KEY NOT NULL,
FIRSTNAME TEXT NOT NULL,
LASTNAME TEXT NOT NULL);''')
self.conn.execute(DbQueries().create_table)
self.conn.close()
except Exception as e:
print(e)
......@@ -20,7 +20,7 @@ class SqliteOperations:
def insert_db(self, frames):
try:
# inserting data to table
frames.to_sql('details', self.conn, if_exists='replace')
frames.to_sql(db_table, self.conn, if_exists='replace')
self.conn.commit()
except Exception as e:
print(e)
......@@ -30,8 +30,8 @@ class SqliteOperations:
# Create a cursor
cursor = self.conn.cursor()
# Execute a SELECT statement to fetch data from the "detaisl" table
cursor.execute("SELECT * FROM details")
# Execute a SELECT statement to fetch data from the "details" table
cursor.execute(DbQueries().select)
return cursor
except Exception as e:
print(e)
......@@ -3,9 +3,9 @@ from fastapi import FastAPI
import json
import pandas as pd
from scripts.config.application_config import topic_name, mqtt_host, port, request_no
from scripts.config.application_config import topic_name, mqtt_host, port, request_no, utf_encode
from scripts.core.handlers.display_data import display_fetched_data
from scripts.utilis.operations_db import SqliteOperations
from scripts.core.handlers.operations_db import SqliteOperations
# This is the Subscriber
......@@ -22,7 +22,7 @@ def receiver():
def on_message(client_name, userdata, msg):
print(client_name, " ", userdata)
# decoding the msg to string
payload_decoded = msg.payload.decode('utf-8')
payload_decoded = msg.payload.decode(utf_encode)
json_data = json.loads(payload_decoded)
# decoded msg to list
data_list = list(json_data.values())
......
# database queries
from scripts.config.application_config import db_table
class DbQueries:
def __init__(self):
# table creation
self.create_table = '''CREATE TABLE IF NOT EXISTS details
(ID INT PRIMARY KEY NOT NULL,
FIRSTNAME TEXT NOT NULL,
LASTNAME TEXT NOT NULL);'''
# table selection
self.select = "SELECT * FROM "+db_table
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment