Commit 1e12fccd by arun.uday

commit1

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (task7)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/task7.iml" filepath="$PROJECT_DIR$/.idea/task7.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
import uvicorn
# starting the application
if __name__ == "__main__":
print("Fast API task")
uvicorn.run("scripts.services.app_services_run:app", port=8000)
[path]
base_path = scripts/
sub_path = temp/
[file]
file_name_csv = MOCK_DATA.csv
file_name_json = data.json
import configparser
config = configparser.RawConfigParser()
config.read("conf/applications.conf")
# path
base_path = config.get("path", 'base_path')
sub_path = config.get("path", "sub_path")
# 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
# dictionary to json
import pandas as pd
import json
def extract_data(csv_file):
data_csv = pd.read_csv(csv_file)
json_data = data_csv.to_dict(orient="records")
return json_data
# remove list from json
def remove_list(json_data_list):
result = json_data_list
dict_cols = {}
for i in range(0, len(result)):
key_dict = i
val_dict = result[i]
dict_cols.update({key_dict: val_dict})
return dict_cols
from fastapi import FastAPI
import json
from scripts.config.application_config import full_path_csv, full_path_json
from scripts.core.handlers.dict_to_json import extract_data
from scripts.core.handlers.remove_list_json import remove_list
from paho.mqtt.client import Client
app = FastAPI()
@app.get("/")
def dict_to_json():
try:
dict_data = extract_data(full_path_csv)
list_removed = remove_list(full_path_json, dict_data)
json_data = json.dumps(list_removed)
client = Client()
client.connect('192.168.0.220', 1883)
client.publish('topic', json_data)
client.disconnect()
except Exception as e:
print(e)
else:
print("Data published")
id,first_name,last_name
1,Marna,Pergens
2,Morie,Iddens
3,Ilysa,Thonger
4,Catherine,Dundendale
5,Randene,Brookz
6,Hester,Yeude
7,Philomena,Dyott
8,Sarene,Petren
9,Rosella,Kinavan
10,El,Creamer
[
{
"id": 1,
"first_name": "Marna",
"last_name": "Pergens"
},
{
"id": 2,
"first_name": "Morie",
"last_name": "Iddens"
},
{
"id": 3,
"first_name": "Ilysa",
"last_name": "Thonger"
},
{
"id": 4,
"first_name": "Catherine",
"last_name": "Dundendale"
},
{
"id": 5,
"first_name": "Randene",
"last_name": "Brookz"
},
{
"id": 6,
"first_name": "Hester",
"last_name": "Yeude"
},
{
"id": 7,
"first_name": "Philomena",
"last_name": "Dyott"
},
{
"id": 8,
"first_name": "Sarene",
"last_name": "Petren"
},
{
"id": 9,
"first_name": "Rosella",
"last_name": "Kinavan"
},
{
"id": 10,
"first_name": "El",
"last_name": "Creamer"
}
]
\ No newline at end of file
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