utils.py 文件源码

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

项目:gwrappy 作者: danielpoonwj 项目源码 文件源码
def load_resp(self, resp, is_download):
        """
        Loads json response from API.

        :param resp: Response from API
        :type resp: dictionary
        :param is_download: Calculates time taken based on 'updated' field in response if upload, and based on stop time if download
        :type is_download: boolean
        """

        assert isinstance(resp, dict)
        setattr(self, 'resp', resp)
        setattr(self, 'size', humanize.naturalsize(int(resp['size'])))

        if is_download:
            updated_at = datetime.now(UTC)
        else:
            updated_at = UTC.localize(datetime.strptime(resp['updated'], '%Y-%m-%dT%H:%M:%S.%fZ'))

        setattr(self, 'time_taken', dict(zip(
            ('m', 's'),
            divmod((updated_at - getattr(self, 'start_time')).seconds if updated_at > getattr(self, 'start_time') else 0, 60)
        )))

        setattr(self, 'full_path', 'gs://%s/%s' % (resp['bucket'], resp['name']))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号