-
Notifications
You must be signed in to change notification settings - Fork 0
/
messaging.py
54 lines (40 loc) · 1.86 KB
/
messaging.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
'''
Created on Apr 2, 2020
@author: Zeeshan
'''
import time, datetime
from queue import Queue
class Channel:
def __init__(self, channel_name, channel_description, capacity):
self.channel_name = channel_name
self.channel_description = channel_description
self.capacity = capacity
self.create_date = time.asctime( time.localtime(time.time()) ) #(datetime.datetime.now()).strftime("%y-%m-%d %H:%M:%S")
self.total_user=0
# Initializing a queue
self.msgQueue = [] #Queue(maxsize=3)
#def addMessage(self, Message):
# if len(self.msgQueue) == self.capacity: #self.msgQueue.full()
# self.msgQueue.pop(0) #self.msgQueue.get_nowait()
#self.msgQueue.put_nowait(Message)
#self.msgQueue.append(Message)
def serialize(self):
return {"channel_name":self.channel_name,
"channel_description":self.channel_description,
"capacity":self.capacity,
"create_date":self.create_date,
"total_user":self.total_user,
"msgQueue": self.msgQueue}
#def __str__(self):
# return f"{{channel_name:{self.channel_name}, channel_description:{self.channel_description}, capacity:{self.capacity}, create_date:{self.create_date}, total_user:{self.total_user}}}"
class Message:
def __init__(self,message, created_by, channel_name):
self.message=message
self.created_by=created_by
self.channel_name = channel_name
self.create_date = (datetime.datetime.now()).strftime("%y-%m-%d %H:%M:%S") #time.asctime( time.localtime(time.time()) )
def serialize(self):
return {"message":self.message,
"created_by":self.created_by,
"channel_name":self.channel_name,
"create_date":self.create_date}