mirror of
https://github.com/ihabunek/toot
synced 2024-12-25 00:20:55 +01:00
Move parsing functions to separate file
This commit is contained in:
parent
2391a39855
commit
f7619d5b22
@ -5,8 +5,9 @@ import webbrowser
|
|||||||
from toot import __version__
|
from toot import __version__
|
||||||
|
|
||||||
from toot.exceptions import ConsoleError
|
from toot.exceptions import ConsoleError
|
||||||
|
from toot.ui.parsers import parse_status
|
||||||
from toot.ui.utils import draw_horizontal_divider, draw_lines
|
from toot.ui.utils import draw_horizontal_divider, draw_lines
|
||||||
from toot.utils import format_content, trunc
|
from toot.utils import trunc
|
||||||
|
|
||||||
# Attempt to load curses, which is not available on windows
|
# Attempt to load curses, which is not available on windows
|
||||||
try:
|
try:
|
||||||
@ -446,33 +447,3 @@ class TimelineApp:
|
|||||||
|
|
||||||
def draw_footer_status(self):
|
def draw_footer_status(self):
|
||||||
self.footer.draw_status(self.selected, len(self.statuses))
|
self.footer.draw_status(self.selected, len(self.statuses))
|
||||||
|
|
||||||
|
|
||||||
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,
|
|
||||||
'media_attachments': _status['media_attachments'],
|
|
||||||
'url': _status['url'],
|
|
||||||
'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'],
|
|
||||||
}
|
|
||||||
|
31
toot/ui/parsers.py
Normal file
31
toot/ui/parsers.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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,
|
||||||
|
'media_attachments': _status['media_attachments'],
|
||||||
|
'url': _status['url'],
|
||||||
|
'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'],
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user