def get(self): # query notify notices = message.get_messages(NIOT, 0, 0, 2, '', 0, 5) # logger.info('notices: {}'.format(notices)) # identify ids = message.get_messages(NIOT, 0, 0, 1, '', 0, 6) # logger.info('ids: {}'.format(ids)) # news news = message.get_messages(NIOT, 0, 0, 3, '', 0, 10) # logger.info('news: {}'.format(news)) self.render('index.html', notices=notices, ids=ids, news=news)
def get(self): # query notify notices = message.get_messages(NIOT, 2, 0, 2, '', 0, 5) # logger.info('notices: {}'.format(notices)) # identify ids = message.get_messages(NIOT, 2, 0, 1, '', 0, 6) # logger.info('ids: {}'.format(ids)) # news news = message.get_messages(NIOT, 2, 0, 3, '', 0, 10) # logger.info('news: {}'.format(news)) self.render('index.html', notices=notices, ids=ids, news=news)
def render_msg(self, page): _id = self.get_argument('id') _message = message.get_message(_id) news = message.get_messages(NIOT, 2, 0, 3, '', 0, 5) if message: self.render('newsdetail.html', _message=_message, news=news) else: self.render('news.html', news=news)
def render_msg(self, page): _id = self.get_argument('id') _message = message.get_message(_id) news = message.get_messages(NIOT, 0, 0, 3, '', 0, 5) if message: self.render('newsdetail.html', _message=_message, news=news) else: self.render('news.html', news=news)
def render_notices(self, page): notices = message.get_messages(NIOT, 2, 0, 2, '', 0, 20) self.render('notices.html', notices=notices)
def render_nameinfo(self, page): ids = message.get_messages(NIOT, 2, 0, 1, '', 0, 20) self.render('nameinfo.html', ids=ids)
def render_news(self, page): ''' ''' news = message.get_messages(NIOT, 2, 0, 3, '', 0, 20) self.render('news.html', news=news)
def prompt_commands(client, user): global USERS """ prompt commands to user """ while True: try: client.send(json.dumps({'command': 'PROMPT_COMMANDS'}).encode('utf-8')) data = client.recv(1024).decode("utf-8") data = data.split(maxsplit=1) command = data[0] with t_lock: if command == 'MSG': # if there are invalid args supplied send error message if len(data) != 2: client.send(json.dumps({ 'command': 'PRINT', 'message': 'MSG: error: Invalid Message!' }).encode("utf-8")) else: # otherwise log the message to the server if the message format is valid res = message.log_message(data[1], user.getUsername()) # send a success message to the client to confirm message has been posted if (res[0]): client.send(json.dumps({ 'command': 'PRINT', 'message': f"Message #{res[1]} posted at {res[2]}" }).encode("utf-8")) else: client.send(json.dumps({ 'command': 'PRINT', 'message': "MSG: error: Invalid Message!" }).encode("utf-8")) elif command == 'EDT': messageInfo = data[1].split() # if there are invalid args supplied if len(messageInfo) < 6: client.send(json.dumps({ 'command': 'PRINT', 'message': 'usage: EDT <messageNumber> <dateTime> <newMessage>' }).encode("utf-8")) else: messageNumber = int(re.findall('\d+',messageInfo[0])[0]) date = ' '.join(messageInfo[1:5]) newMessage=' '.join(messageInfo[5:]) # try to edit the message res = message.edit_message(messageNumber, date, newMessage, user.getUsername()) client.send(json.dumps({ 'command': 'PRINT', 'message': f"{res[1]}" }).encode("utf-8")) elif command == 'DLT': messageInfo = data[1].split(maxsplit=1) if len(messageInfo) < 2: client.send(json.dumps({ 'command': 'PRINT', 'message': 'usage: DLT <messageNumber> <dateTime>' }).encode("utf-8")) else: messageNumber = int(re.findall('\d+',messageInfo[0])[0]) date = messageInfo[1] res = message.delete_message(messageNumber, date, user.getUsername()) client.send(json.dumps({ 'command': 'PRINT', 'message': f"{res[1]}" }).encode("utf-8")) elif command == 'RDM': print(f"> {user.getUsername()} issued RDM command.") if len(data) < 2: client.send(json.dumps({ 'command': 'PRINT', 'message': 'RDM: error: Please specify a date to read from.' }).encode("utf-8")) else: date=data[1] res=message.get_messages(date, user.getUsername()) if res: client.send(json.dumps({ 'command': 'RDM', 'message': res }).encode("utf-8")) else: client.send(json.dumps({ 'command': 'PRINT', 'message': 'No new messages.' }).encode("utf-8")) elif command == 'ATU': # print message to show server has received ATU request print(f"> {user.getUsername()} issued ATU command ATU.") # get the active users list res = getActiveUsersList(user.getUsername()) # if there are other active users send the list to the client if res: client.send(json.dumps({ 'command': 'ATU', 'message': res }).encode("utf-8")) # otherwise notify client of no other active users else: client.send(json.dumps({ 'command': 'PRINT', 'message': 'No other active users.' }).encode("utf-8")) elif command == 'UPD': messageInfo = data[1].split() if len(messageInfo) < 2: client.send(json.dumps({ 'command': 'PRINT', 'message': 'UPD: usage: UPD <targetUser> <fileName>' }).encode("utf-8")) else: targetUser = messageInfo[0] fileName = messageInfo[1] # if the target user is online send the UDP port to the client if getStatus(targetUser): res = getAddress(targetUser) res = list(res) client.send(json.dumps({ 'command': 'UPD', 'message': res, 'filename': fileName, 'username': targetUser }).encode("utf-8")) else: client.send(json.dumps({ 'command': 'PRINT', 'message': 'UPD: error: User is offline.' }).encode("utf-8")) elif command == 'OUT': client_exit(client, user) break else: client.send(json.dumps({'command': 'INVALID_COMMAND'}).encode('utf-8')) t_lock.notify() except: client_exit(client, user) break
def render_notices(self, page): notices = message.get_messages(NIOT, 0, 0, 2, '', 0, 20) self.render('notices.html', notices=notices)
def render_nameinfo(self, page): ids = message.get_messages(NIOT, 0, 0, 1, '', 0, 20) self.render('nameinfo.html', ids=ids)
def render_news(self, page): ''' ''' news = message.get_messages(NIOT, 0, 0, 3, '', 0, 20) self.render('news.html', news=news)