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
1e8db8a9
Commit
1e8db8a9
authored
Mar 29, 2023
by
vipul.v
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mqtt and postgresql updated again
parent
696790ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
44 deletions
+16
-44
script/core/engine/subscriber.py
script/core/engine/subscriber.py
+16
-43
script/core/schema/schema_file.py
script/core/schema/schema_file.py
+0
-1
No files found.
script/core/engine/subscriber.py
View file @
1e8db8a9
...
...
@@ -24,53 +24,27 @@ class MqttConnectPostgresql:
print
(
"Received message on topic '"
+
msg
.
topic
+
"' with message '"
+
msg
.
payload
.
decode
(
'utf-8'
)
+
"'"
)
data
=
json
.
loads
(
msg
.
payload
.
decode
(
'utf-8'
))
print
(
data
)
invoices
=
[]
items
=
[]
for
invoice
in
data
:
invoice_number
=
invoice
[
'invoice_number'
]
client_name
=
invoice
[
'client_name'
]
invoice_date
=
invoice
[
'invoice_date'
]
due_date
=
invoice
[
'due_date'
]
subtotal
=
invoice
[
'subtotal'
]
tax_rate
=
invoice
[
'tax_rate'
]
total
=
invoice
[
'total'
]
paid
=
invoice
[
'paid'
]
invoice_data
=
InvoiceDetails
(
invoice_number
=
invoice
[
'invoice_number'
],
client_name
=
invoice
[
'client_name'
],
invoice_date
=
invoice
[
'invoice_date'
],
due_date
=
invoice
[
'due_date'
],
subtotal
=
invoice
[
'subtotal'
],
tax_rate
=
invoice
[
'tax_rate'
],
total
=
invoice
[
'total'
],
paid
=
invoice
[
'paid'
],
payment_method
=
invoice
.
get
(
'payment_method'
),
if
paid
:
payment_date
=
invoice
[
'payment_date'
]
payment_method
=
invoice
[
'payment_method'
]
billing_address
=
payment_method
[
'billing_address'
]
invoice_data
=
InvoiceDetails
(
invoice_number
=
invoice_number
,
client_name
=
client_name
,
invoice_date
=
invoice_date
,
due_date
=
due_date
,
subtotal
=
subtotal
,
tax_rate
=
tax_rate
,
total
=
total
,
paid
=
paid
,
payment_date
=
payment_date
,
payment_method
=
payment_method
,
billing_address
=
billing_address
)
else
:
invoice_data
=
InvoiceDetails
(
invoice_number
=
invoice_number
,
client_name
=
client_name
,
invoice_date
=
invoice_date
,
due_date
=
due_date
,
subtotal
=
subtotal
,
tax_rate
=
tax_rate
,
total
=
total
,
paid
=
paid
)
)
invoices
.
append
(
invoice_data
)
invoice_id
=
len
(
invoices
)
with
Session
()
as
session
:
session
.
add
(
invoice_data
)
session
.
commit
()
invoice_id
=
invoice_data
.
id
for
item_data
in
invoice
[
'items'
]:
item
=
Items
(
invoice_id
=
invoice_id
,
...
...
@@ -81,7 +55,6 @@ class MqttConnectPostgresql:
items
.
append
(
item
)
with
Session
()
as
session
:
session
.
bulk_save_objects
(
invoices
)
session
.
bulk_save_objects
(
items
)
session
.
commit
()
...
...
@@ -92,4 +65,4 @@ class MqttConnectPostgresql:
client
.
loop_forever
()
except
Exception
as
e
:
print
(
e
,
"Error detected in subscribe"
)
print
(
e
,
"Error detected in subscribe"
)
\ No newline at end of file
script/core/schema/schema_file.py
View file @
1e8db8a9
...
...
@@ -21,7 +21,6 @@ class InvoiceDetails(Base):
paid
=
Column
(
'paid'
,
Boolean
)
payment_date
=
Column
(
'payment_date'
,
Date
)
payment_method
=
Column
(
'payment_method'
,
JSONB
)
billing_address
=
Column
(
'billing_address'
,
JSONB
)
class
Items
(
Base
):
...
...
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