press_sec_bot_plus.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:PressSecBotPlus 作者: robmathers 项目源码 文件源码
def release_tweet(tweet, api):
    """Formats and publishes a Tweet to the account"""

    if tweet.truncated:
        tweet = convert_truncated(tweet)

    tweet_html = render_tweet_html(tweet)
    image = html_to_png(tweet_html)

    status = get_status_message()
    media = []

    # Max 4 photos, or 1 video or 1 GIF

    for media_item in tweet.media or []:
        extra_media_url = 'https://twitter.com/%s/status/%d' % (tweet.user.screen_name, tweet.id)
        if media_item.type == 'video':
            if status != '':
                status += '\n'
            status += '[Video: %s]' % extra_media_url

        elif media_item.type == 'animated_gif':
            if status != '':
                status += '\n'
            status += '[GIF: %s]' % extra_media_url

        elif media_item.type == 'photo':
            if len(media) < 3:
                media.append(media_item.media_url_https)

                # Use large photo size if available
                if media_item.sizes.has_key('large'):
                    media[-1] += ':large'
            else:
                if status != '':
                    status += '\n'
                status += '[Photo: %s]' % extra_media_url

    print(status)
    print(media)

    with NamedTemporaryFile(suffix='.png') as png_file:
        image.save(png_file, format='PNG', dpi=(144,144))
        media.insert(0, png_file)
        api.PostUpdate(status=status, media=media)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号