Commit a0eedd26 by mohammed.shibili

corrections done

parent 5f14357e
import uvicorn
from scripts.config.appconf import api_port
if __name__ == "__main__":
uvicorn.run("scripts.service.ApiCalls:app", port=8000, reload=True)
\ No newline at end of file
uvicorn.run("main:app", port=api_port)
[mongo]
server=mongodb://localhost:27017
database =aggregation
collection =my_table
[end_points]
post_insert=/insert_data
get_violation=/get_violation
get_noViolation=/no_violation
get_to_exel=/to_exel
exel_file=/data.xlsx
[folder_path]
folder=temp
\ No newline at end of file
[api]
api_port=8000
\ No newline at end of file
import uvicorn
from fastapi import FastAPI
from scripts.config.appconf import api_port
from scripts.service.ApiCalls import files, extract
app = FastAPI()
app.include_router(files)
app.include_router(extract)
if __name__ == "__main__":
uvicorn.run(app, port=api_port)
\ No newline at end of file
......@@ -2,5 +2,4 @@ import configparser
config = configparser.RawConfigParser()
config.read("conf/datas.conf")
server_name = config.get("mongo", "server")
db_name = config.get("mongo", "database")
collection_name = config.get("mongo", "collection")
\ No newline at end of file
api_port = int(config.get("api", "api_port"))
import configparser
config = configparser.RawConfigParser()
config.read("conf/datas.conf")
post_insert = config.get("end_points", "post_insert")
get_violation = config.get("end_points", "get_violation")
get_noViolation = config.get("end_points", "get_noViolation")
get_to_exel = config.get("end_points", "get_to_exel")
exel_path = config.get("end_points", "exel_file")
# folder
folder_name = config.get("folder_path", "folder")
class endpoints:
@staticmethod
def api_end():
post_insert = "/insert_data"
get_violation = "/get_violation"
get_noViolation = "/no_violation"
get_to_exel = "/to_exel"
exel_file = "/data.xlsx"
class Endpoints:
post_insert = "/insert_data"
get_violation = "/get_violation"
get_noViolation = "/no_violation"
get_to_exel = "/to_exel"
exel_file = "/data.xlsx"
folder = "temp"
class DbDetails:
db_name = "aggregation"
collection_name = "my_table"
import json
import pandas as pd
from scripts.config.end_points import folder_name, exel_path
from scripts.database.mongo_db.aggregation import aggregation
from scripts.constants.const import Endpoints
from scripts.database.mongo_db.aggregation import Aggregation
from util.mongo_util import mongo_connection
class operations_on_api:
class OperationsOnApi:
def __init__(self):
self.collection_name = mongo_connection()
self.data_violation = aggregation().data_violation()
self.data_no_violation = aggregation().resul_no_violation()
self.data_to_exel = aggregation().exel_conversion()
self.data_violation = Aggregation().data_violation()
self.data_no_violation = Aggregation().resul_no_violation()
self.data_to_exel = Aggregation().exel_conversion()
def data_insert(self, file):
try:
......@@ -37,7 +37,7 @@ class operations_on_api:
try:
values = list(self.collection_name.aggregate(self.data_to_exel))
dataframe = pd.DataFrame(values)
dataframe.to_excel(folder_name + exel_path)
return f'data inserted to path {folder_name}{exel_path}'
dataframe.to_excel(Endpoints().folder + Endpoints().exel_file)
return f'data inserted to path {Endpoints().folder}{Endpoints().exel_file}'
except Exception as e:
return "exel conversion failed", e
class aggregation:
class Aggregation:
# aggregation for violation issued
@staticmethod
def data_violation():
......
from fastapi import FastAPI, UploadFile
from scripts.config.end_points import post_insert, get_violation, get_noViolation, get_to_exel
from scripts.core.handlers.api_function import operations_on_api
from fastapi import APIRouter, UploadFile
from scripts.core.handlers.api_function import OperationsOnApi
from scripts.constants.const import Endpoints
app = FastAPI()
files = APIRouter()
extract = APIRouter()
# for insert datas in file
@app.post(post_insert, tags=['Aggregation'])
@files.post(Endpoints().post_insert, tags=['Aggregation'])
async def post_all(file: UploadFile):
operations_on_api().data_insert(await file.read())
OperationsOnApi().data_insert(await file.read())
return "data inserted"
# to get business name with maximum violation issued
@app.get(get_violation, tags=['Aggregation'])
@extract.get(Endpoints().get_violation, tags=['Aggregation'])
async def get_violation():
print(operations_on_api().violation_issued())
print(OperationsOnApi().violation_issued())
return "data extracted"
# to get business names with no violations
@app.get(get_noViolation, tags=['Aggregation'])
@extract.get(Endpoints().get_noViolation, tags=['Aggregation'])
async def get_no_violation():
print(operations_on_api().no_violation())
print(OperationsOnApi().no_violation())
return "values extracted"
# convert to exel file
@app.get(get_to_exel, tags=['Aggregation'])
@files.get(Endpoints().get_to_exel, tags=['Aggregation'])
async def convert_exel():
print(operations_on_api().create_exel_file())
print(OperationsOnApi().create_exel_file())
return "exel file created"
No preview for this file type
from pymongo import MongoClient
from scripts.config.appconf import db_name, collection_name, server_name
from scripts.config.appconf import server_name
from scripts.constants.const import DbDetails
# creating mongo connection
def mongo_connection():
try:
client = MongoClient(server_name)
database = client[db_name]
collection = database[collection_name]
database = client[DbDetails().db_name]
collection = database[DbDetails().collection_name]
print("connection success")
return collection
except Exception as e:
......
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