models.py 文件源码

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

项目:aurora 作者: carnby 项目源码 文件源码
def from_tweets(cls, tweets, metadata=None, **kwargs):
        """
        :param tweets: a iterable of tweets
        :param kwargs: extra attributes to be considered for inclusion. should be json serializable.
        :return:
        """

        tl = cls()

        json_tweets = json.loads(serializers.serialize("json", tweets));
        for key, values in kwargs.items():
            if len(values) != len(json_tweets):
                continue

            for tweet, value in zip(json_tweets, values):
                tweet['fields'][key] = value

        tl.save()

        json_repr = {'metadata': metadata, 'tweets': json_tweets, 'pk': tl.pk, 'created_at': tl.datetime.isoformat()}
        tl.json = json.dumps(json_repr)
        tl.save()
        return tl
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号