Skip to content

Commit

Permalink
connected to dma-server
Browse files Browse the repository at this point in the history
  • Loading branch information
arrafi-musabbir committed Apr 29, 2021
1 parent 57a71e6 commit bfa083a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Include
Lib
QRs
Scripts
share
.vscode
Include/
Lib/
QRs/
Scripts/
share/
.vscode/
pyvenv.cfg
Radio.gif
run.exe
__pycache__
__pycache__/
python.exe - Shortcut.lnk
\*.json
creds.yml
Expand Down
18 changes: 9 additions & 9 deletions QR_Generator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import qrcode
import os
from PIL import Image
import img2pdf
import image
# from PIL import Image
# import img2pdf


class qrGen:

def __init__(self):
self.qrs_folder_path = os.path.join(os.getcwd(), "QRs")
try:
os.mkdir(self.qrs_folder_path)
except FileExistsError:
pass


def genQR(self, id, sim):
qr = qrcode.QRCode(
Expand All @@ -22,12 +28,6 @@ def genQR(self, id, sim):
# img.show()
self.qr_path = os.path.join(self.qrs_folder_path, (str(sim) + ".png"))
img.save(self.qr_path)
# image = Image.open(self.qr_path)
# pdf_bytes = img2pdf.convert(image.filename)
# file = open(self.qr_path, "wb")
# file.write(pdf_bytes)
# image.close()
# file.close()
# self.printQRCode()

def printQRCode(self):
Expand All @@ -42,4 +42,4 @@ def printImagesInGrid(self):

if __name__ == "__main__":
a = qrGen()
a.genQR(123456, "test")
# a.genQR(123456, "test")
1 change: 0 additions & 1 deletion SerialComm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import serial.tools.list_ports
import serial


class commDev:

def __init__(self):
Expand Down
3 changes: 2 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@
del_all_entries = "Grapics/delete_all_entry.png"
del_entries = "Grapics/delete_entry.png"

key = 'lg747YarfwUIUdiMnjZKme1bTs8FW4Zwy-08slmVBPo='
key = 'lg747YarfwUIUdiMnjZKme1bTs8FW4Zwy-08slmVBPo='
TABLE_NAME = 'init_devices'
19 changes: 10 additions & 9 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@
import socket
from random import randint
import sshtunnel
from config import key
from config import key, TABLE_NAME
import yaml
from cryptography.fernet import Fernet

class database:

def __init__(self):
self.table_name = TABLE_NAME
self.db_state = 0
self.mycursor = None
self.totalIDs = None
self.internetConnectivity = self.checkInternetSocket()

# establish connection to database
def connectDB(self):
global serverINFO
serverINFO = dict()
self.serverINFO = dict()
def decryptServerINFO():
with open('creds.yml', 'r') as file:
serverINFO = yaml.safe_load(file)
a = Fernet(key.encode())
for i in serverINFO:
serverINFO[i] = a.decrypt(serverINFO[i].encode()).decode()
self.serverINFO[i] = a.decrypt(serverINFO[i].encode()).decode()
try:
decryptServerINFO()
self.tunnel = SSHTunnelForwarder((serverINFO['SSH_HOST'], serverINFO['SSH_PORT']),
serverINFO = self.serverINFO
self.tunnel = SSHTunnelForwarder((serverINFO['SSH_HOST'], int(serverINFO['SSH_PORT'])),
ssh_password=serverINFO['SSH_PSWD'],
ssh_username=serverINFO['SSH_UNAME'],
remote_bind_address=(serverINFO['DB_HOST'], serverINFO['DB_PORT']))
remote_bind_address=(serverINFO['DB_HOST'], int(serverINFO['DB_PORT'])))
self.tunnel.start()
self.myDB = mysql.connector.connect(
host=serverINFO['DB_HOST'],
Expand Down Expand Up @@ -70,7 +71,7 @@ def addNew(self, Sim, ID, Password, CreatedOn):

def describeTable(self):
if self.db_state == 1:
self.mycursor.execute("DESCRIBE {}".format(TABLE_NAME))
self.mycursor.execute("DESCRIBE {}".format(self.table_name))
for x in self.mycursor:
print(x)
else:
Expand Down Expand Up @@ -98,7 +99,7 @@ def clearEntries(self, n):
try:
for i in range(n):
self.mycursor.execute(
"DELETE FROM deviceid ORDER BY CreatedOn DESC LIMIT 1")
"DELETE FROM {} ORDER BY CreatedOn DESC LIMIT 1".format(self.table_name))
self.myDB.commit()
print(n, "number of entries deletation succcessfull")
except AttributeError:
Expand All @@ -112,7 +113,7 @@ def getTotalID(self):
try:
# self.mycursor.execute(
# "SELECT Serial FROM deviceid ORDER BY CreatedOn DESC LIMIT 1")
self.mycursor.execute("SELECT * FROM deviceid")
self.mycursor.execute("SELECT * FROM {}".format(self.table_name))
num_rows = self.mycursor.fetchall()
return len(num_rows)

Expand Down

0 comments on commit bfa083a

Please sign in to comment.