def get_number_replies_for_post(self, mid): dao = MessagesDAO() total = dao.get_number_replies_for_post(mid) result_list = [] result = self.build_count_dict(total) result_list.append(result) return jsonify(TotalReplies=result_list)
def getUserReactionsByMessage(self, id, like): dao = MessagesDAO() result = dao.getUsersByMessageReactions(id, like) mappedResult = [] for r in result: mappedResult.append(self.mapUsersToDictionary(r)) return jsonify(Users=mappedResult)
def deletemessage(self, mid): dao = MessagesDAO() if not dao.getMessageById(mid): return jsonify(Error="message not found."), 404 else: dao.delete(mid) return jsonify(DeleteStatus="OK"), 200
def insertReply(self, form, mid, uid, cid): print(form, file=sys.stderr) if len(form) == 1: text = form["mtext"] if text: dao = MessagesDAO() udao = UsersDao() row = dao.post_reply(mid, text, uid, cid) mid = row[0] mdate = row[1] fullname = udao.get_fullname(uid) ufirst_name = fullname[0] ulast_name = fullname[1] new_message = self.build_reply_dict_attributes(mid, text, uid, cid, mdate, ufirst_name, ulast_name) hash_handler = HashtagsHandler() hash_dao = HashtagsDAO() for htext in hash_handler.get_mtext_hashtags(text): hid = hash_dao.search_hashtag(htext) if not hid: hid = hash_dao.post_hashtag(htext) hash_dao.insert_message_contains_hashtag(mid, hid) return jsonify(new_message), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400 else: return jsonify(Error="Malformed post request"), 400
def getUsersLikesOfMessage(self, id, like): dao = MessagesDAO() result = dao.getLikesOfMessage(id, like) mappedResult = [] for r in result: mappedResult.append(self.mapLikesOfMessage(r)) return jsonify(Messages=mappedResult)
def getTopUsers(self): dao = MessagesDAO() result = dao.getTopUsers() mappedResult = [] for r in result: mappedResult.append(self.mapHashtagsToDictionary(r)) return jsonify(TopUsers=mappedResult)
def getAllMessages(self): dao = MessagesDAO() result = dao.getAllMessages() mappedResult = [] for r in result: mappedResult.append(self.mapToDictionary(r)) return jsonify(Messages=mappedResult)
def getHashtagAggregatesWord(self, chat, word): dao = MessagesDAO() result = dao.getHashtagAggregatesSearch(chat, word) mappedResult = [] for r in result: mappedResult.append(self.messagesChatReadyToDictionary(r)) return jsonify(Messages=mappedResult)
def getRepliesPerDate(self, date): dao = MessagesDAO() result = dao.getRepliesPerDate(date) mappedResult = [] for r in result: mappedResult.append(self.mapRepliesToDictionary(r)) return jsonify(Users=mappedResult)
def getAllReplies(self): replyDAO = ReplyDAO() dao1 = MessageDAO() dao2 = MessageDAO() sentDAO = SentDAO() messagesDAO = MessagesDAO() result = replyDAO.getAllReplies() # get all messages that are replies mapped_result = [] #store all replies mapped for r in result: reply_info = [] owner_message = dao1.getMessageById(r[0]) # original message info reply_message = dao2.getMessageById(r[1]) # reply message info reply_info.append(reply_message[1]) # append reply text reply_info.append(owner_message[1]) # append original message replyer_name = sentDAO.getUserByMessageId( reply_message[0]) # get replyer name reply_info.append(replyer_name[1] + ' ' + replyer_name[2]) # append name chat_name = messagesDAO.getChatByMessageId( r[0]) # what group was the reply sent reply_info.append(chat_name[1]) # append group chat name reply_info.append(reply_message[2]) # append reply_date reply_info.append(owner_message[2]) # append original_message_date mapped_result.append(self.mapToDict(reply_info)) return jsonify(Replies=mapped_result)
def createMessage(self, files, form, uid, cid): print(files, file=sys.stderr) print(form, file=sys.stderr) file = files["mimage"] if len(form) == 1 and file: filename = "img" + '_' + str(uid) + '_' + file.filename file.save("static/images/" + filename) image = "static/images/" + filename text = form["mtext"] if image and text: dao = MessagesDAO() udao = UsersDao() row = dao.post_message(image, text, uid, cid) mid = row[0] mdate = row[1] fullname = udao.get_fullname(uid) ufirst_name = fullname[0] ulast_name = fullname[1] new_message = self.build_message_dict_attributes(mid, image, text, uid, cid, mdate, ufirst_name, ulast_name) hash_handler = HashtagsHandler() hash_dao = HashtagsDAO() for htext in hash_handler.get_mtext_hashtags(text): hid = hash_dao.search_hashtag(htext) if not hid: hid = hash_dao.post_hashtag(htext) hash_dao.insert_message_contains_hashtag(mid, hid) return jsonify(new_message), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400 else: return jsonify(Error="Malformed post request"), 400
def repliesPerDay(self): dao = MessagesDAO() trending = dao.repliesPerDay() result_list = [] for row in trending: result = self.build_stats_dict(row) result_list.append(result) return jsonify(Messages=result_list)
def get_replies_per_day(self): dao = MessagesDAO() count_list = dao.get_replies_per_day() result_list = [] for row in count_list: result = self.build_daily_posts_count_dict(row) result_list.append(result) return jsonify(result_list)
def getTrendingTopics(self): dao = MessagesDAO() row = dao.getTrendingTopics() if not row: return jsonify(Error="Message Not Found"), 404 else: result = self.build_trending_dict(row) return jsonify(Trending=result)
def getPostsCount(self): dao = MessagesDAO() trending = dao.getPostsCount() result_list = [] for row in trending: result = self.build_stats_dict(row) result_list.append(result) return jsonify(Messages=result_list)
def getMessagesByGroupId(self, gid): dao = MessagesDAO() messages_list = dao.getMessagesByGroupId(gid) result_list = [] for row in messages_list: result = self.build_message_dict(row) result_list.append(result) return jsonify(Messages=result_list)
def getTrendingTopics(self): dao = MessagesDAO() trending = dao.getTrendingTopics() result_list = [] for row in trending: result = self.build_hashtag_dict(row) result_list.append(result) return jsonify(Messages=result_list)
def get_replies(self, mid): dao = MessagesDAO() replies_list = dao.get_message_replies(mid) result_list = [] for row in replies_list: result = self.build_message_dict(row) result_list.append(result) return jsonify(result_list)
def get_message(self, mid): dao = MessagesDAO() row = dao.get_message(mid) if not row: return jsonify(Error="Message not found"), 404 else: result = self.build_message_dict(row) return jsonify(result)
def get_chat_messages(self, cid): dao = MessagesDAO() messages_list = dao.get_chat_messages(cid) result_list = [] for row in messages_list: result = self.build_message_dict(row) result_list.append(result) return jsonify(result_list)
def get_all_messages(self): dao = MessagesDAO() message_list = dao.get_all_messages() result_list = [] for row in message_list: result = self.build_simple_messege_dict(row) result_list.append(result) return jsonify(result_list)
def getDislikesByMessageId(self, mid): dao = MessagesDAO() row = dao.getDislikesByMessageId(mid) if not row: return jsonify(Error="Message Not Found"), 404 else: dislikes = self.build_message_reaction_dict(row) return jsonify(Dislikes=dislikes)
def getPostsCount(self): dao = MessagesDAO() row = dao.getPostsCount() if not row: return jsonify(Error="Message Not Found"), 404 else: result = self.build_message_count_dict(row) return jsonify(Number=result)
def numReplies(self, oid): dao = MessagesDAO() row = dao.numReplies(oid) if not row: return jsonify(OK="Message Not Found") else: dislikes = self.build_message_reaction_dict(row) return jsonify(Dislikes=dislikes)
def get_posts_per_day_by_user(self, uid): dao = MessagesDAO() count_list = dao.get_posts_per_day_by_user(uid) result_list = [] for row in count_list: result = self.build_daily_posts_count_dict(row) result_list.append(result) return jsonify(result_list)
def getmessageById(self, mid): dao = MessagesDAO() row = dao.getMessageById(mid) if not row: return jsonify(Error="message Not Found"), 404 else: message = self.build_message_dict(row) return jsonify(Message=message)
def getAllmessages(self): dao = MessagesDAO() message_list = dao.getAllMessages() result_list = [] for row in message_list: result = self.build_message_dict(row) result_list.append(result) return jsonify(Messages=result_list)
def getMessageByDate(self, mdate): dao = MessagesDAO() row = dao.getMessageByDate(mdate) if not row: return jsonify(Error="Message Not Found"), 404 else: message = self.build_message_dict(row) return jsonify(Message=message)
def getMessagesByChatId(self, chatId): dao = MessagesDAO() messages_List = dao.getMessagesByChatId(chatId) result_list = [] for row in messages_List: result = self.builMessageDict(row) result_list.append(result) return jsonify(result_list)
def getAllReplies(self): dao = MessagesDAO() messages_List = dao.getAllReplies() result_list = [] for row in messages_List: result = self.buildRepliesDict(row) result_list.append(result) print(row) return jsonify(result_list)