mirror of
https://github.com/ihabunek/toot.git
synced 2024-11-03 04:17:21 -05:00
Move notification printing to output module
Removed sorting, since notifications are already sorted.
This commit is contained in:
parent
204d4d4138
commit
474d9c432f
@ -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("<yellow>No notification</yellow>")
|
||||
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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user