mirror of
https://github.com/ihabunek/toot
synced 2024-12-23 15:37:47 +01:00
5a867f2380
When parsing "replies_count" from status data, we allow the field to be absent as it got added in version 2.5.0 (in constrast with other ones, added in 0.1.0) as there might be servers with that version around.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from toot.utils import format_content
|
|
|
|
|
|
def parse_status(status):
|
|
_status = status.get('reblog') or status
|
|
account = parse_account(_status['account'])
|
|
content = list(format_content(_status['content']))
|
|
spoiler_text = list(format_content(_status['spoiler_text'])) if _status['spoiler_text'] else []
|
|
|
|
created_at = status['created_at'][:19].split('T')
|
|
boosted_by = parse_account(status['account']) if status['reblog'] else None
|
|
|
|
return {
|
|
'account': account,
|
|
'boosted_by': boosted_by,
|
|
'created_at': created_at,
|
|
'content': content,
|
|
'favourited': status.get('favourited'),
|
|
'favourites_count': _status['favourites_count'],
|
|
'id': status['id'],
|
|
'in_reply_to_id': _status.get('in_reply_to_id'),
|
|
'media_attachments': _status['media_attachments'],
|
|
'url': _status['url'],
|
|
'reblogged': status.get('reblogged'),
|
|
'reblogs_count': _status['reblogs_count'],
|
|
'replies_count': _status.get('replies_count', 0),
|
|
'spoiler_text': spoiler_text,
|
|
'sensitive': _status['sensitive'],
|
|
'show_sensitive': False,
|
|
}
|
|
|
|
|
|
def parse_account(account):
|
|
return {
|
|
'id': account['id'],
|
|
'acct': account['acct'],
|
|
'display_name': account['display_name'],
|
|
}
|