crawler.py 文件源码

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

项目:MercrediFiction 作者: Meewan 项目源码 文件源码
def save_account(instance, content):
    username = content['username']
    if not USERNAME_REGEX.match(username):
        username = '[invalid_username]'
    domain = instance.domain
    acct = "@" + username + "@" + domain
    if Account.query.filter_by(username=acct).count() != 0:
        return Account.query.filter_by(username=acct).first()
    else:
        creation_date = datetime.strptime(content['created_at'],
                                          "%Y-%m-%dT%H:%M:%S.%fZ")
        account = Account(mastodon_id=content['id'],
                          username=acct,
                          display_name=to_text(content['display_name']),
                          creation_date=creation_date,
                          note=to_text(content['note']),
                          url=validate_url(content['url']),
                          avatar=validate_url(content['avatar']),
                          instance=instance,
                          blacklisted=False)
        save(account)
        return account
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号