models.py 文件源码

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

项目:Strassengezwitscher 作者: Strassengezwitscher 项目源码 文件源码
def clean(self):
        # remove leading @
        if self.name.startswith('@'):
            self.name = self.name[1:]

        twitter = TwitterAPI(settings.TWITTER_CONSUMER_KEY,
                             settings.TWITTER_CONSUMER_SECRET,
                             auth_type='oAuth2')
        try:
            user = twitter.request('users/show', {'screen_name': self.name}).json()
        except TwitterConnectionError:
            logger.warning("Could not connect to Twitter.")
            raise ValidationError("Could not connect to Twitter to retrieve user_id.")
        if 'id' in user:
            self.account_id = user['id']
        else:
            logger.warning("Could not find user with provided name.")
            raise ValidationError("Could not find user with provided name.")

        if TwitterAccount.objects.filter(account_id=self.account_id):
            logger.warning("TwitterAccount with account_id is already in database.")
            raise ValidationError("Twitter account with this name already exists.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号