publish_playlist_twitter.py 文件源码

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

项目:homemadescripts 作者: helioloureiro 项目源码 文件源码
def TwitterPost(video_info):
    # App python-tweeter
    # https://dev.twitter.com/apps/815176
    tw = twitter.Api(
        consumer_key = cons_key,
        consumer_secret = cons_sec,
        access_token_key = acc_key,
        access_token_secret = acc_sec
    )
    title = video_info.keys()[0]
    print "Title: %s" % title
    image = video_info[title]['thumb']
    print "Image: %s" % image
    url = video_info[title]['url']
    print "Video: %s" % url
    fd, file_image = tempfile.mkstemp()
    GetImage(image, fd)
    msg = "Watch again: %s\n%s #pyconse" % (title, url)
    print "Posting: %s" % msg
    print "Image: %s" % file_image
    try:
        tw.PostMedia(status = msg,media = file_image)
        os.unlink(file_image)
    except twitter.TwitterError as err:
        # twitter.TwitterError: [{u'message': u'Status is a duplicate.', u'code': 187}]
        print "ERROR: %s" % err.args[0][0]['message']
        print "Post on Twitter failed. Trying again..."
        if os.path.exists(file_image):
            os.unlink(file_image)
        video = GetVideo()
        TwitterPost(video)
        return
    try:
        msg = "Don't forget to send you talk proposal for #pyconse (September 6th in Stockholm). key=%d " % random.randint(1000,5000) + \
            "https://goo.gl/RjHpoS"
        print "Posting: %s" % msg
        tw.PostUpdate(msg)
    except twitter.TwitterError as err:
        error = err.args[0][0]
        print "ERROR: %s" % error['message']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号