Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JSON using MQTT and PostgreSQL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vipul.v
JSON using MQTT and PostgreSQL
Commits
696790ee
Commit
696790ee
authored
Mar 29, 2023
by
vipul.v
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mqtt and postgresql updated
parent
da156f22
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
0 deletions
+107
-0
app.py
app.py
+13
-0
script/core/handlers/handler_file.py
script/core/handlers/handler_file.py
+17
-0
script/core/schema/responses.py
script/core/schema/responses.py
+9
-0
script/service/service_file.py
script/service/service_file.py
+23
-0
script/utils/utils_file.py
script/utils/utils_file.py
+45
-0
No files found.
app.py
0 → 100644
View file @
696790ee
from
dotenv
import
load_dotenv
from
fastapi
import
FastAPI
from
script.config.app_confing
import
Service
from
script.service.service_file
import
router
load_dotenv
()
app
=
FastAPI
(
title
=
"fetch"
)
app
.
include_router
(
router
)
if
__name__
==
"__main__"
:
import
uvicorn
uvicorn
.
run
(
"app:app"
,
host
=
Service
.
host
,
port
=
Service
.
port
)
\ No newline at end of file
script/core/handlers/handler_file.py
0 → 100644
View file @
696790ee
from
sqlalchemy
import
MetaData
from
script.utils.utils_file
import
SqlUtility
metadata
=
MetaData
()
SqlUtility
=
SqlUtility
()
class
FetchRecords
:
@
staticmethod
def
fetch_records
():
try
:
data
=
SqlUtility
.
fetch_file
()
return
data
except
Exception
as
e
:
print
(
e
,
"Error detected in fetching the data"
)
script/core/schema/responses.py
0 → 100644
View file @
696790ee
from
typing
import
Any
,
Optional
from
pydantic
import
BaseModel
class
DefaultResponse
(
BaseModel
):
status
:
str
=
"failed"
message
:
str
data
:
Optional
[
Any
]
script/service/service_file.py
0 → 100644
View file @
696790ee
import
logging
from
fastapi
import
APIRouter
from
script.constants
import
APIEndpoints
from
script.core.errors
import
ErrorMessage
from
script.core.handlers.handler_file
import
FetchRecords
from
script.core.schema.responses
import
DefaultResponse
router
=
APIRouter
(
prefix
=
APIEndpoints
.
fetch_records
)
handler
=
FetchRecords
()
@
router
.
post
(
APIEndpoints
.
find
)
async
def
fetch_item
():
try
:
data
=
handler
.
fetch_records
()
return
DefaultResponse
(
message
=
"Successfully Found"
,
status
=
"success"
,
data
=
data
)
except
ValueError
:
return
DefaultResponse
(
message
=
ErrorMessage
.
ERRORS_FETCH
)
except
Exception
as
e
:
logging
.
exception
(
e
)
return
DefaultResponse
(
message
=
"Finding Failed due to server error"
)
\ No newline at end of file
script/utils/utils_file.py
0 → 100644
View file @
696790ee
from
sqlalchemy
import
MetaData
,
inspect
from
script.core.db.postgresql_connector
import
session
,
engine
from
script.core.schema.schema_file
import
InvoiceDetails
,
Items
metadata
=
MetaData
()
class
SqlUtility
:
@
staticmethod
def
fetch_file
():
try
:
inspector
=
inspect
(
engine
)
columns
=
inspector
.
get_columns
(
'invoice_details'
)
column_names
=
[
c
[
'name'
]
for
c
in
columns
]
invoice_details
=
session
.
query
(
InvoiceDetails
)
.
all
()
body
=
[]
for
data
in
invoice_details
:
row
=
{}
for
column_name
in
column_names
:
row
[
column_name
]
=
getattr
(
data
,
column_name
)
body
.
append
(
row
)
header
=
[]
for
column_name
in
column_names
:
title_name
=
column_name
.
replace
(
'_'
,
' '
)
.
title
()
header
.
append
({
"label"
:
title_name
,
"value"
:
column_name
})
columns2
=
inspector
.
get_columns
(
'items'
)
column_names2
=
[
c
[
'name'
]
for
c
in
columns2
]
items
=
session
.
query
(
Items
)
.
all
()
body2
=
[]
for
data
in
items
:
row
=
{}
for
column_name
in
column_names2
:
row
[
column_name
]
=
getattr
(
data
,
column_name
)
body2
.
append
(
row
)
header2
=
[]
for
column_name
in
column_names2
:
title_name
=
column_name
.
replace
(
'_'
,
' '
)
.
title
()
header2
.
append
({
"label"
:
title_name
,
"value"
:
column_name
})
return
{
"headerContent"
:
header
,
"bodyContent"
:
body
,
"headerContent2"
:
header2
,
"bodyContent2"
:
body2
}
except
Exception
as
e
:
print
(
e
,
"Error detected in updating"
)
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