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
da156f22
Commit
da156f22
authored
Mar 29, 2023
by
vipul.v
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mqtt and postgresql updated
parent
ece4100a
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
80 additions
and
15 deletions
+80
-15
.idea/sonarlint/issuestore/index.pb
.idea/sonarlint/issuestore/index.pb
+19
-0
.idea/sonarlint/securityhotspotstore/index.pb
.idea/sonarlint/securityhotspotstore/index.pb
+19
-0
.idea/vcs.xml
.idea/vcs.xml
+6
-0
conf/application.conf
conf/application.conf
+5
-1
main.py
main.py
+1
-1
script/config/app_confing.py
script/config/app_confing.py
+8
-3
script/constants/__init__.py
script/constants/__init__.py
+3
-0
script/core/engine/subscriber.py
script/core/engine/subscriber.py
+16
-9
script/core/errors/__init__.py
script/core/errors/__init__.py
+2
-0
script/core/schema/schema_file.py
script/core/schema/schema_file.py
+1
-1
No files found.
.idea/sonarlint/issuestore/index.pb
View file @
da156f22
_
/venv/Lib/site-packages/sqlalchemy/sql/schema.py,0\3\03c17c8487ae787ca54e1068612ee0449fb2336d
J
script/core/db/__init__.py,2\2\22d1021820e124f6ade661fc6dbdc53bbdb563bc
\
,.idea/inspectionProfiles/Project_Default.xml,4\9\496a238a6afa168dbaf6efd37bb459331589579c
N
script/core/schema/__init__.py,8\4\84b7e789bb411a2f2e44fa4f79362bae15a9ca5e
4
.env,3\c\3c84dcdc6bbe3d7817c49dcdc327b926fea1808a
C
billing_output.json,a\6\a6c9aad7bfecc10410ad99e3c4d541b2e9626b69
^
..idea/inspectionProfiles/profiles_settings.xml,1\e\1e9075f5bf079c01ef2c910709e91a497d262080
S
#.idea/sonarlint/issuestore/index.pb,9\f\9fe84ebb15faf917b7def6236dba604453cc61e0
]
-.idea/sonarlint/securityhotspotstore/index.pb,8\8\88a9255124c95bdc913197c120a8d560edc59c8e
\ No newline at end of file
.idea/sonarlint/securityhotspotstore/index.pb
View file @
da156f22
_
/venv/Lib/site-packages/sqlalchemy/sql/schema.py,0\3\03c17c8487ae787ca54e1068612ee0449fb2336d
J
script/core/db/__init__.py,2\2\22d1021820e124f6ade661fc6dbdc53bbdb563bc
\
,.idea/inspectionProfiles/Project_Default.xml,4\9\496a238a6afa168dbaf6efd37bb459331589579c
N
script/core/schema/__init__.py,8\4\84b7e789bb411a2f2e44fa4f79362bae15a9ca5e
4
.env,3\c\3c84dcdc6bbe3d7817c49dcdc327b926fea1808a
C
billing_output.json,a\6\a6c9aad7bfecc10410ad99e3c4d541b2e9626b69
^
..idea/inspectionProfiles/profiles_settings.xml,1\e\1e9075f5bf079c01ef2c910709e91a497d262080
S
#.idea/sonarlint/issuestore/index.pb,9\f\9fe84ebb15faf917b7def6236dba604453cc61e0
]
-.idea/sonarlint/securityhotspotstore/index.pb,8\8\88a9255124c95bdc913197c120a8d560edc59c8e
\ No newline at end of file
.idea/vcs.xml
0 → 100644
View file @
da156f22
<?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
conf/application.conf
View file @
da156f22
[
MQTT_SERVICE
]
[
MQTT_SERVICE
]
broker_host
=
192
.
168
.
0
.
220
broker_host
=
192
.
168
.
0
.
220
broker_port
=
1883
broker_port
=
1883
\ No newline at end of file
[
SERVICE
]
port
=
8000
host
=
0
.
0
.
0
.
0
\ No newline at end of file
main.py
View file @
da156f22
from
script.core.engine.subscriber
import
MqttConnectPostgresql
from
script.core.engine.subscriber
import
MqttConnectPostgresql
mqtt_data
=
MqttConnectPostgresql
()
mqtt_data
=
MqttConnectPostgresql
()
mqtt_data
.
mqtt_file
()
mqtt_data
.
mqtt_file
()
\ No newline at end of file
script/config/app_confing.py
View file @
da156f22
from
dotenv
import
load_dotenv
import
os
import
os
from
configparser
import
SafeConfigParser
from
configparser
import
SafeConfigParser
from
dotenv
import
load_dotenv
load_dotenv
()
load_dotenv
()
config
=
SafeConfigParser
()
config
=
SafeConfigParser
()
config
.
read
(
'conf/application.conf'
)
config
.
read
(
'conf/application.conf'
)
class
Sql
:
class
Sql
:
postgresql
:
str
=
os
.
environ
.
get
(
"POSTGRESQL_URI"
)
postgresql
:
str
=
os
.
environ
.
get
(
"POSTGRESQL_URI"
)
class
Services
:
class
Services
:
host
=
config
.
get
(
"MQTT_SERVICE"
,
"broker_host"
)
host
=
config
.
get
(
"MQTT_SERVICE"
,
"broker_host"
)
port
=
int
(
config
.
get
(
"MQTT_SERVICE"
,
"broker_port"
))
port
=
int
(
config
.
get
(
"MQTT_SERVICE"
,
"broker_port"
))
\ No newline at end of file
class
Service
:
port
=
int
(
config
.
getint
(
"SERVICE"
,
"port"
))
host
=
config
.
get
(
"SERVICE"
,
"host"
)
script/constants/__init__.py
View file @
da156f22
class
APIEndpoints
:
find
=
"/find"
fetch_records
=
"/fetch_records"
\ No newline at end of file
script/core/engine/subscriber.py
View file @
da156f22
import
json
import
json
import
paho.mqtt.client
as
mqtt
import
paho.mqtt.client
as
mqtt
from
sqlalchemy.orm
import
sessionmaker
from
script.config.app_confing
import
Services
from
script.config.app_confing
import
Services
from
script.core.db.postgresql_connector
import
session
from
script.core.db.postgresql_connector
import
engine
from
script.core.schema.schema_file
import
Items
,
InvoiceDetails
from
script.core.schema.schema_file
import
Items
,
InvoiceDetails
# subscribe
Session
=
sessionmaker
(
bind
=
engine
)
topic
=
"test/#"
topic
=
"test/#"
...
@@ -25,6 +25,9 @@ class MqttConnectPostgresql:
...
@@ -25,6 +25,9 @@ class MqttConnectPostgresql:
"Received message on topic '"
+
msg
.
topic
+
"' with message '"
+
msg
.
payload
.
decode
(
'utf-8'
)
+
"'"
)
"Received message on topic '"
+
msg
.
topic
+
"' with message '"
+
msg
.
payload
.
decode
(
'utf-8'
)
+
"'"
)
data
=
json
.
loads
(
msg
.
payload
.
decode
(
'utf-8'
))
data
=
json
.
loads
(
msg
.
payload
.
decode
(
'utf-8'
))
print
(
data
)
print
(
data
)
invoices
=
[]
items
=
[]
for
invoice
in
data
:
for
invoice
in
data
:
invoice_number
=
invoice
[
'invoice_number'
]
invoice_number
=
invoice
[
'invoice_number'
]
client_name
=
invoice
[
'client_name'
]
client_name
=
invoice
[
'client_name'
]
...
@@ -64,9 +67,10 @@ class MqttConnectPostgresql:
...
@@ -64,9 +67,10 @@ class MqttConnectPostgresql:
total
=
total
,
total
=
total
,
paid
=
paid
paid
=
paid
)
)
session
.
add
(
invoice_data
)
invoices
.
append
(
invoice_data
)
session
.
flush
()
invoice_id
=
invoice_data
.
id
invoice_id
=
len
(
invoices
)
for
item_data
in
invoice
[
'items'
]:
for
item_data
in
invoice
[
'items'
]:
item
=
Items
(
item
=
Items
(
invoice_id
=
invoice_id
,
invoice_id
=
invoice_id
,
...
@@ -74,8 +78,12 @@ class MqttConnectPostgresql:
...
@@ -74,8 +78,12 @@ class MqttConnectPostgresql:
quantity
=
item_data
[
'quantity'
],
quantity
=
item_data
[
'quantity'
],
price
=
item_data
[
'price'
]
price
=
item_data
[
'price'
]
)
)
session
.
add
(
item
)
items
.
append
(
item
)
session
.
commit
()
with
Session
()
as
session
:
session
.
bulk_save_objects
(
invoices
)
session
.
bulk_save_objects
(
items
)
session
.
commit
()
client
=
mqtt
.
Client
()
client
=
mqtt
.
Client
()
client
.
on_connect
=
on_connect
client
.
on_connect
=
on_connect
...
@@ -85,4 +93,3 @@ class MqttConnectPostgresql:
...
@@ -85,4 +93,3 @@ class MqttConnectPostgresql:
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
,
"Error detected in subscribe"
)
print
(
e
,
"Error detected in subscribe"
)
script/core/errors/__init__.py
View file @
da156f22
class
ErrorMessage
(
Exception
):
ERRORS_FETCH
=
"Due to value error in fetch"
\ No newline at end of file
script/core/schema/schema_file.py
View file @
da156f22
...
@@ -13,7 +13,7 @@ class InvoiceDetails(Base):
...
@@ -13,7 +13,7 @@ class InvoiceDetails(Base):
id
=
Column
(
'id'
,
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
id
=
Column
(
'id'
,
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
invoice_number
=
Column
(
'invoice_number'
,
String
,
unique
=
True
)
invoice_number
=
Column
(
'invoice_number'
,
String
,
unique
=
True
)
client_name
=
Column
(
'client_name'
,
String
)
client_name
=
Column
(
'client_name'
,
String
)
invoice_date
=
Column
(
'invoice_dat
a
'
,
Date
)
invoice_date
=
Column
(
'invoice_dat
e
'
,
Date
)
due_date
=
Column
(
'due_date'
,
Date
)
due_date
=
Column
(
'due_date'
,
Date
)
subtotal
=
Column
(
'subtotal'
,
Integer
)
subtotal
=
Column
(
'subtotal'
,
Integer
)
tax_rate
=
Column
(
'tax_rate'
,
Float
)
tax_rate
=
Column
(
'tax_rate'
,
Float
)
...
...
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