-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodel.py
More file actions
53 lines (45 loc) · 1.36 KB
/
model.py
File metadata and controls
53 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pymysql
import datetime
import flask
import operator
from mysql import connector
from sqlite3 import OperationalError
db_config = {
'host': 'localhost',
'user': 'root',
'password': 'LoginPass@@12',
'database': 'DogsTinder'
}
class DBManager():
connection: pymysql.Connection = None
@classmethod
def getConnection(cls):
return cls.connection
@classmethod
def getCursor(cls):
try:
if not cls.connection or not cls.connection.open:
cls.connection = pymysql.connect(**db_config)
except OperationalError:
cls.connection.close
return cls.connection.cursor()
@classmethod
def closeConnection(cls):
if cls.connection and cls.connection.open:
cls.connection.close()
class Message:
def __init__(self, sender, receiver, content, date:datetime, meeting_proposal):
self.id = None
self.sender = sender
self.receiver = receiver
self.content = content
self.date = date
self.meeting_proposal = meeting_proposal
def serialize(self) -> dict:
return {
'id': self.id,
'sender': self.sender,
'receiver': self.receiver,
'content': self.content,
'date': self.date
}