Пример #1
0
def twitter_card(userid):
    username, full_name, catchphrase, profile_text, config, twitter = d.execute(
        "SELECT pr.username, pr.full_name, pr.catchphrase, pr.profile_text, pr.config, ul.link_value "
        "FROM profile pr "
        "LEFT JOIN user_links ul ON pr.userid = ul.userid AND ul.link_type = 'twitter' "
        "WHERE pr.userid = %i", [userid], ["single"])

    ret = {
        'card': 'summary',
        'url': d.absolutify_url('/~%s' % (username, )),
        'title': '%s on Weasyl' % (full_name, ),
    }

    if catchphrase:
        description = '"%s"' % (catchphrase, )
    elif profile_text:
        description = strip_html(profile_text)
    else:
        description = "[%s has an empty profile, but is eggcelent!]" % (
            full_name, )
    ret['description'] = d.summarize(description)

    media_items = media.get_user_media(userid)
    ret['image:src'] = d.absolutify_url(
        media_items['avatar'][0]['display_url'])

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'), )

    return ret
Пример #2
0
def twitter_card(userid):
    username, full_name, catchphrase, profile_text, config, twitter = d.execute(
        "SELECT pr.username, pr.full_name, pr.catchphrase, pr.profile_text, pr.config, ul.link_value "
        "FROM profile pr "
        "LEFT JOIN user_links ul ON pr.userid = ul.userid AND ul.link_type = 'twitter' "
        "WHERE pr.userid = %i",
        [userid],
        ["single"])

    ret = {
        'card': 'summary',
        'url': d.absolutify_url('/~%s' % (username,)),
        'title': '%s on Weasyl' % (full_name,),
    }

    if catchphrase:
        description = '"%s"' % (catchphrase,)
    elif profile_text:
        description = strip_html(profile_text)
    else:
        description = "[%s has an empty profile, but is eggcelent!]" % (full_name,)
    ret['description'] = d.summarize(description)

    media_items = media.get_user_media(userid)
    ret['image:src'] = d.absolutify_url(media_items['avatar'][0]['display_url'])

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'),)

    return ret
Пример #3
0
def twitter_card(submitid):
    query = d.execute(
        """
        SELECT
            su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter'
        WHERE submitid = %i
        LIMIT 1
    """, [submitid], ["single"])

    if not query:
        raise WeasylError("submissionRecordMissing")
    title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query
    if 'h' in settings:
        raise WeasylError("submissionRecordMissing")
    elif 'f' in settings:
        raise WeasylError("FriendsOnly")

    if 'v' in settings:
        content = d.text_first_line(content, strip=True)
    content = d.summarize(html.strip_html(content))
    if not content:
        content = "[This submission has no description.]"

    ret = {
        'url':
        d.absolutify_url('/submission/%s/%s' %
                         (submitid, text.slug_for(title))),
    }

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'), )
        ret['title'] = title
    else:
        ret['title'] = '%s by %s' % (title, full_name)

    if ratings.CODE_MAP[rating].minimum_age >= 18:
        ret['card'] = 'summary'
        ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com'
        return ret

    ret['description'] = content

    subcat = subtype / 1000 * 1000
    media_items = media.get_submission_media(submitid)
    if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'):
        ret['card'] = 'photo'
        ret['image:src'] = d.absolutify_url(
            media_items['submission'][0]['display_url'])
    else:
        ret['card'] = 'summary'
        thumb = media_items.get('thumbnail-custom') or media_items.get(
            'thumbnail-generated')
        if thumb:
            ret['image:src'] = d.absolutify_url(thumb[0]['display_url'])

    return ret
Пример #4
0
def twitter_card(submitid):
    query = d.execute("""
        SELECT
            su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter'
        WHERE submitid = %i
        LIMIT 1
    """, [submitid], ["single"])

    if not query:
        raise WeasylError("submissionRecordMissing")
    title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query
    if 'h' in settings:
        raise WeasylError("submissionRecordMissing")
    elif 'f' in settings:
        raise WeasylError("FriendsOnly")

    if 'v' in settings:
        content = d.text_first_line(content, strip=True)
    content = d.summarize(html.strip_html(content))
    if not content:
        content = "[This submission has no description.]"

    ret = {
        'url': d.absolutify_url(
            '/submission/%s/%s' % (submitid, text.slug_for(title))),
    }

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'),)
        ret['title'] = title
    else:
        ret['title'] = '%s by %s' % (title, full_name)

    if ratings.CODE_MAP[rating].minimum_age >= 18:
        ret['card'] = 'summary'
        ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com'
        return ret

    ret['description'] = content

    subcat = subtype / 1000 * 1000
    media_items = media.get_submission_media(submitid)
    if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'):
        ret['card'] = 'photo'
        ret['image:src'] = d.absolutify_url(media_items['submission'][0]['display_url'])
    else:
        ret['card'] = 'summary'
        thumb = media_items.get('thumbnail-custom') or media_items.get('thumbnail-generated')
        if thumb:
            ret['image:src'] = d.absolutify_url(thumb[0]['display_url'])

    return ret