Пример #1
0
def m_to_string(v):
    if isempty(v):
        return escape_html(BLANK)
    elif isinstance(v, str):
        return escape_html(v)
    elif isinstance(v, bytes):
        return escape_html(v.decode('utf8', 'replace'))
    else:
        return escape_html(SEPARATOR.join(v))
Пример #2
0
def m_to_string(v):
    if isempty(v):
        return escape_html(BLANK)
    elif isinstance(v, unicode):
        return escape_html(v)
    elif isinstance(v, str):
        return escape_html(v.decode('utf8', 'replace'))
    else:
        return escape_html(SEPARATOR.join(v))
Пример #3
0
def _render_issues(conn, *types):
    cursor = conn.cursor()
    types_sql = ", ".join(["'{}'".format(x) for x in types])
    cursor.execute(_issues_sql.format(types_sql))

    records = cursor.fetchall()

    if not records:
        return "<div class=\"none\">None</div>"

    lines = list()

    for record in records:
        args = escape_html(record[1]), record[0], escape_html(record[2])
        lines.append(" - [{}]({}) - {}".format(*args))

    return "\n".join(lines)
Пример #4
0
def main(sourceurl, username=None, password=None):
    """
    Given a reddit JSON url, yield unicode strings that represent the
    exported HTML
    """
    yield header_template % dict(exported_url=escape_html(sourceurl))

    cookie = None

    if username and password:
        cookie = login(username, password)

    for link in get_links(sourceurl, cookie):
        data = link["data"]

        if link["kind"] == "t3":
            # links

            template_data = dict(
                id=escape_html(data["id"]),
                url=escape_html(data["url"]),
                title=escape_html(data["title"]),
                domain=escape_html(data["domain"]),
                author=escape_html(data["author"]),
                subreddit=escape_html(data["subreddit"]),
                score=int(data["score"]),
                num_comments=int(data["num_comments"]),
                date=time.ctime(data["created_utc"]),
                selftext_template="",
            )

            if data.get("is_self", False):
                # This is the only way to tell if it's a self-post from
                # the API :-/
                template_data["domain_link"] = "http://www.reddit.com/r/%(subreddit)s" % dict(
                    subreddit=escape_html(data["subreddit"])
                )
            else:
                template_data["domain_link"] = "http://www.reddit.com/domain/%(domain)s" % dict(
                    domain=escape_html(data["domain"])
                )

            if data.get("selftext_html"):
                selftext = selftext_template % unescape_html(data["selftext_html"])
                template_data["selftext_template"] = selftext

            yield link_template % template_data

        elif link["kind"] == "t1":
            # comments

            template_data = dict(
                body=unescape_html(data["body_html"]),
                author=escape_html(data["author"]),
                subreddit=escape_html(data["subreddit"]),
                id=escape_html(data["id"]),
                score=int(data["ups"]) - int(data["downs"]),
                date=time.ctime(data["created_utc"]),
                link_id36=escape_html(data["link_id"].split("_")[1]),
            )

            yield comment_template % template_data

        else:
            raise TypeError("I don't know how to decode %r" % link)

    yield footer_template
Пример #5
0
def esc(o):
    return escape_html(unicode(o))
Пример #6
0
def render_item(record):
    args = record[0], escape_html(record[1]), escape_html(record[2])
    return "<li><a href='%s'>%s</a> - %s</li>" % args
Пример #7
0
def esc(o):
    return escape_html(unicode(o))
Пример #8
0
def main(sourceurl, username=None, password=None):
    '''
    Given a reddit JSON url, yield unicode strings that represent the
    exported HTML
    '''
    yield header_template % dict(exported_url=escape_html(sourceurl))

    cookie = None

    if username and password:
        cookie = login(username, password)

    for link in get_links(sourceurl, cookie):
        data = link['data']

        if link['kind'] == 't3':
            # links

            template_data = dict(
                id=escape_html(data['id']),
                url=escape_html(data['url']),
                title=escape_html(data['title']),
                domain=escape_html(data['domain']),
                author=escape_html(data['author']),
                subreddit=escape_html(data['subreddit']),
                score=int(data['score']),
                num_comments=int(data['num_comments']),
                date=time.ctime(data['created_utc']),
                selftext_template='',
            )

            if data.get('is_self', False):
                # This is the only way to tell if it's a self-post from
                # the API :-/
                template_data['domain_link'] = (
                    'http://www.reddit.com/r/%(subreddit)s' %
                    dict(subreddit=escape_html(data['subreddit'])))
            else:
                template_data['domain_link'] = (
                    'http://www.reddit.com/domain/%(domain)s' %
                    dict(domain=escape_html(data['domain'])))

            if data.get('selftext_html'):
                selftext = selftext_template % unescape_html(
                    data['selftext_html'])
                template_data['selftext_template'] = selftext

            yield link_template % template_data

        elif link['kind'] == 't1':
            # comments

            template_data = dict(
                body=unescape_html(data['body_html']),
                author=escape_html(data['author']),
                subreddit=escape_html(data['subreddit']),
                id=escape_html(data['id']),
                score=int(data['ups']) - int(data['downs']),
                date=time.ctime(data['created_utc']),
                link_id36=escape_html(data['link_id'].split('_')[1]),
            )

            yield comment_template % template_data

        else:
            raise TypeError("I don't know how to decode %r" % link)

    yield footer_template
Пример #9
0
def main(sourceurl, username = None, password = None):
    '''
    Given a reddit JSON url, yield unicode strings that represent the
    exported HTML
    '''
    yield header_template % dict(exported_url = escape_html(sourceurl))

    cookie = None

    if username and password:
        cookie = login(username, password)

    for link in get_links(sourceurl, cookie):
        data = link['data']

        if link['kind'] == 't3':
            # links

            template_data = dict(
                id = escape_html(data['id']),
                url = escape_html(data['url']),
                title = escape_html(data['title']),
                domain = escape_html(data['domain']),
                author = escape_html(data['author']),
                subreddit = escape_html(data['subreddit']),
                score = int(data['score']),
                num_comments = int(data['num_comments']),
                date = time.ctime(data['created_utc']),
                selftext_template = '',
                )

            if data.get('is_self', False):
                # This is the only way to tell if it's a self-post from
                # the API :-/
                template_data['domain_link'] = (
                    'http://www.reddit.com/r/%(subreddit)s'
                    % dict(subreddit = escape_html(data['subreddit'])))
            else:
                template_data['domain_link'] = (
                    'http://www.reddit.com/domain/%(domain)s'
                    % dict(domain = escape_html(data['domain'])))

            if data.get('selftext_html'):
                selftext = selftext_template % unescape_html(data['selftext_html'])
                template_data['selftext_template'] = selftext

            yield link_template % template_data

        elif link['kind'] == 't1':
            # comments

            template_data = dict(body = unescape_html(data['body_html']),
                                 author = escape_html(data['author']),
                                 subreddit = escape_html(data['subreddit']),
                                 id = escape_html(data['id']),
                                 score = int(data['ups']) - int(data['downs']),
                                 date = time.ctime(data['created_utc']),
                                 link_id36 = escape_html(data['link_id'].split('_')[1]),
                                 )

            yield comment_template % template_data

        else:
            raise TypeError("I don't know how to decode %r" % link)

    yield footer_template