当前位置: 首页>>代码示例>>Python>>正文


Python APIClient.post方法代码示例

本文整理汇总了Python中weibo.APIClient.post方法的典型用法代码示例。如果您正苦于以下问题:Python APIClient.post方法的具体用法?Python APIClient.post怎么用?Python APIClient.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weibo.APIClient的用法示例。


在下文中一共展示了APIClient.post方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import post [as 别名]
    def post(self):
        import logging
        import hashlib
        import hmac
        import logging
        import re
        from StringIO import StringIO
        from time import time
        from urllib2 import urlopen
        from django.utils import simplejson

        from weibo import APIClient

        payload = self.request.body

        # verify payload
        signature = self.request.headers['X-Hub-Signature']
        client_secret = settings.INSTAGRAM_CONFIG['client_secret']
        hashing_obj= hmac.new(client_secret.encode("utf-8"),
            msg = payload.encode("utf-8"),
            digestmod = hashlib.sha1)
        digest = hashing_obj.hexdigest()

        if digest != signature:
            logging.info("Digest and signature differ. (%s, %s)"
                % (digest, signature))
            return

        changes = simplejson.loads(payload)
        for change in changes:
            profiles = Profile.all()
            profiles.filter("ig_user_id =", change['object_id'])
            profile = profiles.get()

            if not profile:
                logging.info("Cannot find profile %s", change['object_id'])
                continue

            instagram_client = InstagramAPI(
                    access_token = profile.ig_access_token)

            media, _ = instagram_client.user_recent_media(count = 1)
            media = media[0]

            # filter
            if "instahust" not in map(lambda x: x.name, media.tags): return

            media_file = urlopen(media.images['standard_resolution'].url)
            media_data = media_file.read()

            pic_file = StringIO(media_data)
            weibo_text = media.caption.text
            # rip hashtag & strip whitespace
            weibo_text = re.sub(r"#(\w+)", "", weibo_text).strip()
            instagram_author = media.user.username
            instagram_url = media.link

            weibo_content = u"#instahust#%s (by %s) %s" % \
                            (weibo_text, instagram_author, instagram_url)

            weibo_client = APIClient(settings.WEIBO_GSID)
            weibo_client.post(content=weibo_content, pic=pic_file)
开发者ID:GZShi,项目名称:instahust,代码行数:64,代码来源:handlers.py


注:本文中的weibo.APIClient.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。