diff --git a/toot/commands.py b/toot/commands.py index d0f5f2a..a4d7d86 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- -from datetime import datetime - from toot import api, config from toot.auth import login_interactive, login_browser_interactive, create_app_interactive from toot.exceptions import ConsoleError, NotFoundError from toot.output import (print_out, print_instance, print_account, - print_search_results, print_status, print_timeline) + print_search_results, print_timeline, print_notifications) from toot.utils import assert_domain_exists, multiline_input, EOF_KEY @@ -309,23 +307,4 @@ def notifications(app, user, args): print_out("No notification") return - width = 100 - for notification in sorted(notifications, - key=lambda n: datetime.strptime( - n["created_at"], "%Y-%m-%dT%H:%M:%S.%fZ"), - reverse=True): - account = "{display_name} @{acct}".format(**notification["account"]) - msg = { - "follow": "{account} now follows you", - "mention": "{account} mentioned you in", - "reblog": "{account} reblogged your status", - "favourite": "{account} favourited your status", - }.get(notification["type"]) - if msg is None: - continue - print_out("─" * width) - print_out(msg.format(account=account)) - status = notification.get("status") - if status is not None: - print_status(status, width=width) - print_out("─" * width) + print_notifications(notifications) diff --git a/toot/output.py b/toot/output.py index 87a8a63..2a52e77 100644 --- a/toot/output.py +++ b/toot/output.py @@ -175,3 +175,30 @@ def print_timeline(items, width=100): for item in items: print_status(item, width) print_out("─" * width) + + +notification_msgs = { + "follow": "{account} now follows you", + "mention": "{account} mentioned you in", + "reblog": "{account} reblogged your status", + "favourite": "{account} favourited your status", +} + + +def print_notification(notification, width=100): + account = "{display_name} @{acct}".format(**notification["account"]) + msg = notification_msgs.get(notification["type"]) + if msg is None: + return + + print_out("─" * width) + print_out(msg.format(account=account)) + status = notification.get("status") + if status is not None: + print_status(status, width) + + +def print_notifications(notifications, width=100): + for notification in notifications: + print_notification(notification) + print_out("─" * width)