Commit 4f6b3a9a by arun.uday

commit5

parent b7921ea4
......@@ -15,8 +15,9 @@ handlers_path = config.get("path", "handlers_path")
file_name_csv = config.get("file", "file_name_csv")
file_name_json = config.get("file", "file_name_json")
file_mode = config.get("file", "file_mode")
full_path_csv = base_path + sub_path + file_name_csv
full_path_json = base_path + sub_path + file_name_json
full_path = base_path + sub_path
full_path_csv = full_path + file_name_csv
full_path_json = full_path + file_name_json
# mqtt
topic_name = config.get("mqtt", "topic")
......
......@@ -2,10 +2,14 @@
import pandas as pd
from scripts.config.application_config import orientation
from scripts.logging.loggers import logger
# extracting the csv to dictionary
def extract_data(csv_file):
try:
data_csv = pd.read_csv(csv_file)
json_data = data_csv.to_dict(orient=orientation)
return json_data
except Exception as e:
logger.error("Some exception occurred while reding the csv file: ", e)
......@@ -5,9 +5,11 @@ from paho.mqtt.client import Client
from scripts.config import application_config
from scripts.core.handlers.dict_to_json import extract_data
from scripts.core.handlers.remove_list_json import remove_list
from scripts.logging.loggers import logger
def extract_send_data():
try:
dict_data = extract_data(application_config.full_path_csv)
list_removed = remove_list(dict_data)
......@@ -16,3 +18,5 @@ def extract_send_data():
client.connect(application_config.mqtt_host, int(application_config.mqtt_port))
client.publish(application_config.topic_name, json_data)
client.disconnect()
except Exception as e:
logger.error("Some exception occurred while sending file: ", e)
# remove list from json
from scripts.logging.loggers import logger
def remove_list(json_data_list):
try:
result = json_data_list
dict_cols = {}
for i in range(0, len(result)):
......@@ -7,3 +11,5 @@ def remove_list(json_data_list):
val_dict = result[i]
dict_cols.update({key_dict: val_dict})
return dict_cols
except Exception as e:
logger.error("Some exception occurred while converting json to dictionary: ", e)
# file upload to csv
from scripts.config.application_config import file_mode
from scripts.logging.loggers import logger
def extract_uploaded_data(full_path_csv, file_data):
try:
with open(full_path_csv, file_mode) as file_object:
file_object.write(file_data.file.read())
except Exception as e:
logger.error("Some exception occurred while reading the file: ", e)
......@@ -17,7 +17,7 @@ def get_logger():
formatter = logging.Formatter(log_formatter, time_format)
if not os.path.exists(file_path):
os.makedirs(file_path)
log_file = os.path.join(f"{file_path}{application_config.db_name}.log")
log_file = os.path.join(f"{file_path}{application_config.topic_name}.log")
temp_handler = RotatingFileHandler(log_file, maxBytes=1)
temp_handler.setFormatter(formatter)
__logger__.addHandler(temp_handler)
......
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