Exemplo n.º 1
0
 def get(self, note_id):
     template_values = {}
     if len(note_id) < 8:
         raise tornado.web.HTTPError(404)
     note_id = decode(note_id)
     notes = self.db.query(
             "select title,note,rev_num,rev_user_name as name,rev_user_domain as domain"
             ", revdate from fd_NoteHistory where note_id = %s and rev_status = 0"
             " order by rev_num desc", note_id)
     if not notes:
         raise tornado.web.HTTPError(404)
     for i in range(len(notes)):
         next_note = {}
         if i == len(notes)-1:
             next_note['title'] = ''
             next_note['note'] = ''
         else:
             next_note['title'] = notes[i+1].title
             next_note['note'] = notes[i+1].note
         notes[i].title = textdiff(xhtml_escape(next_note['title']), xhtml_escape(notes[i].title))
         note1 = self.br(linkify(next_note['note'], extra_params="target='_blank' rel='nofollow'"))
         note2 = self.br(linkify(notes[i].note, extra_params="target='_blank' rel='nofollow'"))
         notes[i].note = self.at(textdiff(note1, note2))
         notes[i]['rev'] = 0
         if i == 0:
             notes[i]['rev'] = 1
     template_values['notes'] = notes
     self.render("notehistory.html", template_values=template_values)
Exemplo n.º 2
0
 def post(self, status_id):
     if len(status_id) < 8:
         raise tornado.web.HTTPError(404)
     status_id = decode(status_id)
     comments = self.get_argument("commenttext", None)
     user_id = self.current_user.id
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     comment_id = self.db.execute(
         "insert into fd_Stacomm (user_id, "
         " status_id, comments, pubdate) values (%s,%s,%s,%s)", user_id,
         status_id, comments, pubdate)
     if comment_id:
         status_key = self.rd.keys('status*%s' % status_id)[0]
         prev_comments_num = self.rd.hget(status_key, 'comm')
         if not prev_comments_num:
             comments_num = 1
         else:
             comments_num = int(prev_comments_num) + 1
         self.rd.hset(status_key, 'comm', comments_num)
         self.write(''.join([
             self.avatar('m', self.current_user.id,
                         self.current_user.uuid_), ',',
             self.br(
                 self.at(
                     linkify(
                         comments,
                         extra_params="target='_blank' rel='nofollow'")))
         ]))
Exemplo n.º 3
0
def wrap(u):
    """Given a unicode, return a unicode.
    """
    typecheck(u, unicode)
    u = linkify(u)  # Do this first, because it calls xthml_escape.
    u = u.replace(u'\r\n', u'<br />\r\n').replace(u'\n', u'<br />\n')
    return u if u else '...'
Exemplo n.º 4
0
 def post(self):
     status = self.get_argument("statustext", None)
     if not status: raise tornado.web.HTTPError(405)
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     redpubdate = pubdate[4:] if pubdate[3] == '0' else pubdate[3:]
     user_id = self.current_user.id
     status_id = self.db.execute(
         "insert into fd_Status (user_id, "
         " status, pubdate) values (%s,%s,%s)", user_id, status, pubdate)
     #redis
     if status_id:
         actdict = {'time': redpubdate, 'status': status}
         addresult = add_activity(self.rd, user_id, status_id, 1, actdict)
         if addresult:
             self.write(''.join([
                 encode(str(status_id)), ',',
                 self.avatar('m', self.current_user.id,
                             self.current_user.uuid_), ',',
                 self.br(
                     self.at(
                         linkify(
                             status,
                             extra_params="target='_blank' rel='nofollow'"))
                 )
             ]))
         else:
             self.write("Something wrong...")
Exemplo n.º 5
0
def wrap(u):
    """Given a unicode, return a unicode.
    """
    typecheck(u, unicode)
    u = linkify(u)  # Do this first, because it calls xthml_escape.
    u = u.replace(u'\r\n', u'<br />\r\n').replace(u'\n', u'<br />\n')
    return u if u else '...'
Exemplo n.º 6
0
def wrap(u):
    """Given a unicode, return a unicode.
    """
    typecheck(u, unicode)
    u = linkify(u)  # Do this first, because it calls xthml_escape.
    u = u.replace(u"\r\n", u"<br />\r\n").replace(u"\n", u"<br />\n")
    return u if u else "..."
Exemplo n.º 7
0
    def get_description(self, raw=False):
        """
        Returns desciption, escapes double quotes if sans_quotes is True, used
        for rendering description inside fields.
        """
        description = self.description
        if not description:
            description = ''

        if not raw:
            #description = escape.xhtml_escape(description)
            extra_params = 'target="_blank" rel="nofollow"'

            description = escape.linkify(description,
                                         True,
                                         extra_params=extra_params)

            #re_hash = re.compile(r'#[0-9a-zA-Z+]*',re.IGNORECASE)
            #for iterator in re_hash.finditer(description):

            description = re.sub(r'(\A|\s)#(\w+)',
                                 r'\1<a href="/tag/\2">#\2</a>', description)

            description = description.replace('\n', '<br>')
        return description
Exemplo n.º 8
0
 def get(self):
     noteid = self.get_argument("note_id",None)
     if not noteid or len(noteid) < 8:
         raise tornado.web.HTTPError(404)
     noteid = decode(noteid)
     note = self.db.get("select note from fd_Note where "
             "id = %s", noteid)
     if note:
         self.write(self.br(self.at(linkify(note.note, extra_params="target='_blank' rel='nofollow'"))))
     else:
         self.write("wrong")
Exemplo n.º 9
0
def chatbot_response(text):
    res3 = ""
    res1 = ""
    res = ""
    ints = predict_class(text, model)
    res = getResponse(ints, intents)
    #    t=ints[0]['intent']
    #    text=text.lower()
    #    tags=['oxygen ','beds','plasma','medicine','ambulance']
    #
    #    for tag in tags :
    #        if t==tag:
    #            res3=tagg(tag,text)
    #    res1=str(res+"\n"+ res3)
    return linkify(res)
Exemplo n.º 10
0
    def broadcast_chat_message(self, user, message):
        # first linkify
        message_text = linkify(to_unicode(message), extra_params='target="_blank"', require_protocol=False)
        # last find shortcode emojis
        message_text = emoji.shortcode_to_unicode(message_text)
        # then find ascii emojis
        message_text = emoji.ascii_to_unicode(message_text)

        new_message = {'user': user,
                       'color': users[user]['color'],
                       'message': message_text,
                       'time': time.time()}
        history.append(new_message)
        self.broadcast(self.participants, {'type': 'chatMessage',
                                           'data': new_message})
Exemplo n.º 11
0
 def body_formatted(self):
     """
     An escaped and formatted body of the comment with \n replaced by HTML <br>
     """
     #body = escape.xhtml_escape(self.body)
     #print body
     #body = escape.linkify(body, True) #someday?
     #for now use Bleach
     #bl = Bleach()
     #body = bl.linkify(body, nofollow=True)
     #body = body.replace('</a>/', '/</a>')
     #body = body.replace('<a href=', '<a target="_blank" href=')
     body = escape.linkify(self.body,
                           True,
                           extra_params='rel="nofollow" target="_blank"')
     body = body.replace('\n', '<br>')
     return body
Exemplo n.º 12
0
def preprocess_message(message, emoji_processor):
    message_text = message

    # first linkify
    message_text = linkify(to_unicode(message_text),
                           extra_params='target="_blank"',
                           require_protocol=False)
    # last find shortcode emojis
    message_text = emoji_processor.shortcode_to_unicode(message_text)
    # then find ascii emojis
    message_text = emoji_processor.ascii_to_unicode(message_text)
    # remove any raw script, audio, or video tags that are left
    if message.find('<script') >= 0 or message.find(
            '<audio') >= 0 or message.find('<video') >= 0 or message.find(
                '<iframe') >= 0 or message.find('<img') >= 0:
        message_text = xhtml_escape(message_text)

    return message_text
Exemplo n.º 13
0
    def post(self, *args, **kwargs):
        """ New notice """
        street = self.get_secure_cookie('street')
        if not street:
            self.send_error(403)

        notice = {
            'dated': bson.timestamp.Timestamp(datetime.now(),0),
            'name': self.get_secure_cookie('name'),
            'street': street,
        }

        if self.get_argument('type') == 'checkin':
            notice['type'] = 'checkin'
        else:
            notice['type'] = self.get_argument('type')
            notice['message'] = linkify(self.get_argument('message'))

        mc.notices.insert(notice)

        self.redirect('/')
Exemplo n.º 14
0
 def render(self, text, hl, **kwargs):
     for wd in hl:
         text = re.sub(r'\b({})\b'.format(wd),
                       '<span style="color:red">{}</span>'.format(wd), text)
     return escape.xhtml_unescape(escape.linkify(text, **kwargs))
Exemplo n.º 15
0
    def create(self, user, body, scope, via=None):
        from user.models import User
        soup = BeautifulSoup(body, 'lxml')
        body = " ".join(soup.stripped_strings)

        message = {}
        message['scope'] = scope
        message['body'] = linkify(body, extra_params='target="_blank"')
        message['body'], mentions = User.objects.replace_mention(message['body'])
        message['author_id'] = user.id
        message['author_fullname'] = user.fullname
        message['author_username'] = user.username
        message['author_pic'] = user.pic
        message['likes'] = 0

        via_user = None
        if via and via != user.username:
            # it's a repost
            via_user = User.objects.find(username=via)
            message['via_username'] = via
            message['via_fullname'] = via_user.fullname

        msg_obj = Message(**message)

        result = _URL_RE.search(body)
        if result:
            try:
                url = result.group()
                http_client = AsyncHTTPClient()
                response = yield http_client.fetch(url)
                soup = BeautifulSoup(response.body, 'lxml')

                try:
                    oembed_link = soup.find('link', {'rel': 'alternate', 'type': 'application/json+oembed'}).attrs['href']
                    http_client = AsyncHTTPClient()
                    oembed = yield http_client.fetch(oembed_link)
                    json = json_decode(oembed.body)
                    msg_obj.add_link(url, json['title'], json['thumbnail_url'],
                                     json['thumbnail_width'], json['thumbnail_height'])
                except:
                    title = soup.title
                    if title:
                        msg_obj.add_link(url, title.string)
            except:
                pass

        msg_obj.save()
        user.incr_message_count()
        user.push_message(msg_obj)
        if via_user:
            Notification.objects.create(user.fullname,
                                        'reposted',
                                        msg_obj.id,
                                        via_user.id)
        for u in mentions:
            Notification.objects.create(user.fullname,
                                        'mentioned',
                                        msg_obj.id,
                                        u.id)

        return msg_obj
Exemplo n.º 16
0
def linkify(text, extra_params=""):
    from tornado.escape import linkify
    return linkify(text, extra_params=extra_params)    
Exemplo n.º 17
0
 def body_html(self):
     b = decodestring(self.body)
     b = b.replace("\n", "<br />")
     b = xhtml_unescape(linkify(b, extra_params='target="_blank"'))
     return b
Exemplo n.º 18
0
 def post(self):
     status = self.get_argument("statustext",None)
     if not status: raise tornado.web.HTTPError(405)
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     redpubdate = pubdate[4:] if pubdate[3] == '0' else pubdate[3:]
     user_id = self.current_user.id
     status_id = self.db.execute("insert into fd_Status (user_id, "
                 " status, pubdate) values (%s,%s,%s)", user_id, 
                 status, pubdate)
     #redis
     if status_id:
         actdict = {'time':redpubdate, 'status':status}
         addresult = add_activity(self.rd, user_id, status_id, 1, actdict)
         if addresult:
             self.write(''.join([encode(str(status_id)), ',', self.avatar('m',self.current_user.id,self.current_user.uuid_),',', self.br(self.at(linkify(status, extra_params="target='_blank' rel='nofollow'")))]))
         else:
             self.write("Something wrong...")
Exemplo n.º 19
0
 def post(self, link_id):
     if len(link_id) < 8:
         raise tornado.web.HTTPError(404)
     link_id = decode(link_id)
     comments = self.get_argument("commenttext",None)
     user_id = self.current_user.id
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     comment_id = self.db.execute("insert into fd_Linkcomm (user_id, "
                 " link_id, comments, pubdate) values (%s,%s,%s,%s)", 
                 user_id, link_id, comments, pubdate)
     if comment_id:
         link_key = self.rd.keys('link*%s' % link_id)[0]
         prev_comments_num = self.rd.hget(link_key, 'comm')
         if not prev_comments_num:
             comments_num = 1
         else:
             comments_num = int(prev_comments_num) + 1
         self.rd.hset(link_key, 'comm', comments_num)
         self.write(''.join([self.avatar('m',self.current_user.id,self.current_user.uuid_), ',', self.br(self.at(linkify(comments, extra_params="target='_blank' rel='nofollow'")))]))
Exemplo n.º 20
0
def linkify(text, extra_params=""):
    from tornado.escape import linkify
    return linkify(text, extra_params=extra_params)