-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
88 lines (79 loc) · 2.51 KB
/
model.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
from SubcriptionToSNS import checkConfirm
class Items :
def __init__(self, dynamodb ,NAMETABLE):
table = dynamodb.Table(NAMETABLE)
response = table.scan()
self.tablename = NAMETABLE
self.listItems = response
self.names = response['Items']
self.count = response['Count']
def listItem (self):
print(json.dumps(self.listItems, indent=4) )
def getcountItem (self):
print('Number of items in table : '+ self.count)
return self.count
def getlistItemNames (self):
return self.names
class DynamoDb :
def __init__(self ,dynamodb ,nametable , name=None,email=None):
self.dynamodb = dynamodb
self.nametable = nametable
self.name = name
self.email = email
def loadDATA (self):
LISTACCOUNT = []
list = Items(self.dynamodb,self.nametable)
for obj in list.getlistItemNames() :
status = ""
if checkConfirm(obj['Email']) == True:
status = r'style=color:green'
acc = Account( obj['Name'],obj['Email'],status)
LISTACCOUNT.append(acc)
return LISTACCOUNT
def addAccount (self):
try :
table = self.dynamodb.Table(self.nametable)
response = table.put_item(
Item = {
'Name': self.name,
'Email': self.email
}
)
return True
except:
print("Tao tai khoan khong thanh cong !")
return False
def deleteAccount (self):
try :
table = self.dynamodb.Table(self.nametable)
response = table.delete_item(
Key = {
'Name': self.name,
'Email': self.email
})
print(response)
return True
except:
print("Tai khoan khong ton tai !")
return False
def readAccount (self):
try :
table = self.dynamodb.Table(self.nametable)
response = table.get_item(
Key={
'Name': self.name,
'Email': self.email
}
)
resp = response['Item']
print(resp)
return resp
except:
print("Tai khoan khong ton tai !")
return None
class Account :
def __init__(self, name, email, status):
self.name = name
self.email = email
self.status = status