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
评论列表
文章目录