Exemple #1
0
 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)
Exemple #2
0
 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
Exemple #4
0
 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
Exemple #5
0
 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)
Exemple #6
0
 def getTopUsers(self):
     dao = MessagesDAO()
     result = dao.getTopUsers()
     mappedResult = []
     for r in result:
         mappedResult.append(self.mapHashtagsToDictionary(r))
     return jsonify(TopUsers=mappedResult)
Exemple #7
0
 def getAllMessages(self):
     dao = MessagesDAO()
     result = dao.getAllMessages()
     mappedResult = []
     for r in result:
         mappedResult.append(self.mapToDictionary(r))
     return jsonify(Messages=mappedResult)
Exemple #8
0
 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)
Exemple #9
0
 def getRepliesPerDate(self, date):
     dao = MessagesDAO()
     result = dao.getRepliesPerDate(date)
     mappedResult = []
     for r in result:
         mappedResult.append(self.mapRepliesToDictionary(r))
     return jsonify(Users=mappedResult)
Exemple #10
0
    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)
Exemple #11
0
 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)
Exemple #13
0
 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)
Exemple #14
0
 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)
Exemple #18
0
 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)
Exemple #19
0
 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)
Exemple #20
0
 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)
Exemple #21
0
 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)
Exemple #23
0
 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)
Exemple #24
0
 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)
Exemple #25
0
 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)
Exemple #29
0
    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)
Exemple #30
0
 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)