Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Mongo-Aggregations
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arjun.b
Mongo-Aggregations
Commits
55b72480
Commit
55b72480
authored
Feb 06, 2023
by
arjun.b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging file added
parent
b9bdfab5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
5 deletions
+46
-5
conf/application.conf
+2
-0
main.py
+0
-0
scripts/config/application_config.py
+4
-0
scripts/logging/logging.py
+27
-0
scripts/services/mongo_services.py
+13
-5
No files found.
conf/application.conf
View file @
55b72480
...
...
@@ -5,3 +5,5 @@ port_no=8000
uri
=
mongodb
://
localhost
:
27017
[
file_path
]
path
=
temp
/
excel_data
.
xlsx
[
logging
]
file_name
=
scripts
/
external
/
logging_log
main.py
deleted
100644 → 0
View file @
b9bdfab5
scripts/config/application_config.py
View file @
55b72480
...
...
@@ -3,9 +3,13 @@ import configparser
try
:
config
=
configparser
.
ConfigParser
()
config
.
read
(
"conf/application.conf"
)
# server path
server_path
=
config
.
get
(
"server"
,
"server_path"
)
port_no
=
config
.
get
(
"server"
,
"port_no"
)
# mongo pth
uri
=
config
.
get
(
"mongo"
,
"uri"
)
file_path
=
config
.
get
(
"file_path"
,
"path"
)
# logging file path
file_name
=
config
.
get
(
"logging"
,
"file_name"
)
except
configparser
.
NoOptionError
:
print
(
"could not find conf file"
)
scripts/logging/logging.py
0 → 100644
View file @
55b72480
import
logging
import
os
from
logging.handlers
import
RotatingFileHandler
from
scripts.config.application_config
import
file_name
def
get_logger
():
"""
Creates a rotating log
"""
__logger__
=
logging
.
getLogger
(
''
)
__logger__
.
setLevel
(
"ERROR"
)
log_formatter
=
'
%(asctime)
s -
%(levelname)-6
s - [
%(threadName)5
s:
%(funcName)5
s():
%(lineno)
s] -
%(message)
s'
time_format
=
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
formatter
=
logging
.
Formatter
(
log_formatter
,
time_format
)
log_file
=
os
.
path
.
join
(
f
"{file_name}_ERROR.log"
)
temp_handler
=
RotatingFileHandler
(
log_file
,
maxBytes
=
100000000
,
backupCount
=
5
)
temp_handler
.
setFormatter
(
formatter
)
__logger__
.
addHandler
(
temp_handler
)
return
__logger__
logger
=
get_logger
()
scripts/services/mongo_services.py
View file @
55b72480
from
fastapi
import
FastAPI
,
UploadFile
from
scripts.constants.end_points
import
APIEndpoints
from
scripts.database.mongo.mongo_aggregation
import
max_violation
,
no_violation
from
scripts.core.handlers.mongo_handlers
import
MongoHandler
from
fastapi
import
FastAPI
,
UploadFile
from
scripts.constants.end_points
import
APIEndpoints
from
scripts.core.handlers.mongo_handlers
import
MongoHandler
from
scripts.database.mongo.mongo_aggregation
import
max_violation
,
no_violation
from
scripts.logging.logging
import
logger
app
=
FastAPI
(
title
=
"Mongo Aggregations"
)
...
...
@@ -29,19 +25,31 @@ async def upload_file(file: UploadFile):
# business name with maximum violation
@app.get
(
APIEndpoints
.
max_violation
,
tags
=
[
"tasks"
])
async
def
business_max_violation
():
try
:
re
=
max_violation
()
return
{
"data"
:
re
}
except
Exception
as
e
:
logger
.
error
(
"cant find business name with max violation"
)
print
(
e
)
# business name with no violation
@app.get
(
APIEndpoints
.
no_violation
,
tags
=
[
"tasks"
])
async
def
business_no_violation
():
try
:
re
=
no_violation
()
return
{
"data"
:
re
}
except
Exception
as
e
:
logger
.
error
(
"cant find business name with no violation"
)
print
(
e
)
# create Excel file
@app.get
(
APIEndpoints
.
convert_excel
,
tags
=
[
"convert to excel"
])
async
def
convert_excel
():
try
:
MongoHandler
.
create_excel_file
()
return
{
"data"
,
"Excel file generated based on business name,result and date"
}
except
Exception
as
e
:
logger
.
error
(
"cant create excel file"
)
print
(
e
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment