コード例 #1
0
 def get_messages_with_hashtag(self, hid):
     dao = HashtagsDAO()
     messages = dao.get_messages_with_hashtag(hid)
     result = []
     for message in messages:
         dict = self.build_message_dict(message)
         result.append(dict)
     return jsonify(Messages=result)
コード例 #2
0
 def get_hashtag_by_id(self, hid):
     dao = HashtagsDAO()
     hashtag = dao.get_hashtag_by_id(hid)
     if not hashtag:
         return jsonify(Error="Hashtag not found"), 404
     else:
         result = self.build_hashtag_dict(hashtag)
         return jsonify(Hashtag=result)
コード例 #3
0
 def get_hashtags_for_message(self, mid):
     dao = HashtagsDAO()
     hashtags = dao.get_hashtags_per_message(mid)
     result = []
     for hashtag in hashtags:
         dict = self.build_hashtag_dict(hashtag)
         result.append(dict)
     return jsonify(Hashtag=result)
コード例 #4
0
 def get_trending(self):
     dao = HashtagsDAO()
     trending = dao.get_trending_hashtags()
     result = []
     for hashtag in trending:
         dict = self.build_trending_dict(hashtag)
         result.append(dict)
     return jsonify(result)
コード例 #5
0
 def get_hashtags(self):
     dao = HashtagsDAO()
     hashtags = dao.get_hashtags()
     result = []
     for hashtag in hashtags:
         dict = self.build_hashtag_dict(hashtag)
         result.append(dict)
     return jsonify(Hashtags=result)
コード例 #6
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
コード例 #7
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
コード例 #8
0
 def get_times_used(self, hid):
     dao = HashtagsDAO()
     times_used = dao.get_times_used(hid)
     return jsonify(Used=times_used)