Beispiel #1
0
def post_content():
    if not session.get('user'):
        return redirect('/')

    room_id = request.form.get('room_id')
    data = {'user': session.get('user'),
            'content': linkify(escape_text(request.form.get('content', ''))),
            'created': time.strftime('%m-%d %H:%M:%S'),
            'room_id': room_id,
            'id': rc.incr(config.ROOM_CONTENT_INCR_KEY),
            }
    rc.zadd(config.ROOM_CHANNEL.format(room=room_id), json.dumps(data), time.time())
    return jsonify(**data)
Beispiel #2
0
def post_content():
    if not session.get('user'):
        return redirect('/')

    room_id = request.form.get('room_id')
    data = {
        'user': session.get('user'),
        'content': linkify(escape_text(request.form.get('content', ''))),
        'created': time.strftime('%m-%d %H:%M:%S'),
        'room_id': room_id,
        'id': rc.incr(config.ROOM_CONTENT_INCR_KEY),
    }
    rc.zadd(config.ROOM_CHANNEL.format(room=room_id), json.dumps(data),
            time.time())
    return jsonify(**data)
Beispiel #3
0
                #url = proto_part + host_part  + "/" + \
                        #parts[1][:8].split('?')[0].split('.')[0]

            if len(url) > max_len * 1.5:  # still too long
                url = url[:max_len]

            if url != before_clip:
                amp = url.rfind('&')
                # avoid splitting html char entities
                if amp > max_len - 5:
                    url = url[:amp]
                url += "..."

                if len(url) >= len(before_clip):
                    url = before_clip
                else:
                    # full url is visible on mouse-over (for those who don't
                    # have a status bar, such as Safari by default)
                    params += ' title="%s"' % href

        return u'<a href="%s"%s>%s</a>' % (href, params, url)

    return RE_URL.sub(make_link, txt)

if __name__ == '__main__':
    txt = 'have a link test www.zhihu.com/question/19550224?noti_id=123 how about?'
    txt1 = 'hello http://tornadoweb.org!'
    print linkify(txt)

########NEW FILE########
Beispiel #4
0
                #parts[1][:8].split('?')[0].split('.')[0]

            if len(url) > max_len * 1.5:  # still too long
                url = url[:max_len]

            if url != before_clip:
                amp = url.rfind('&')
                # avoid splitting html char entities
                if amp > max_len - 5:
                    url = url[:amp]
                url += "..."

                if len(url) >= len(before_clip):
                    url = before_clip
                else:
                    # full url is visible on mouse-over (for those who don't
                    # have a status bar, such as Safari by default)
                    params += ' title="%s"' % href

        return u'<a href="%s"%s>%s</a>' % (href, params, url)

    return RE_URL.sub(make_link, txt)


if __name__ == '__main__':
    txt = 'have a link test www.zhihu.com/question/19550224?noti_id=123 how about?'
    txt1 = 'hello http://tornadoweb.org!'
    print linkify(txt)

########NEW FILE########