kopia lustrzana https://github.com/ihabunek/toot
Add --json option to notifications
rodzic
e960267b70
commit
4b88b86b6f
|
@ -697,9 +697,9 @@ def verify_credentials(app, user) -> Response:
|
||||||
return http.get(app, user, '/api/v1/accounts/verify_credentials')
|
return http.get(app, user, '/api/v1/accounts/verify_credentials')
|
||||||
|
|
||||||
|
|
||||||
def get_notifications(app, user, types=[], exclude_types=[], limit=20):
|
def get_notifications(app, user, types=[], exclude_types=[], limit=20) -> Response:
|
||||||
params = {"types[]": types, "exclude_types[]": exclude_types, "limit": limit}
|
params = {"types[]": types, "exclude_types[]": exclude_types, "limit": limit}
|
||||||
return http.get(app, user, '/api/v1/notifications', params).json()
|
return http.get(app, user, '/api/v1/notifications', params)
|
||||||
|
|
||||||
|
|
||||||
def clear_notifications(app, user):
|
def clear_notifications(app, user):
|
||||||
|
|
|
@ -2,12 +2,12 @@ import sys
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from toot import api
|
from toot import api
|
||||||
from toot.cli import InstanceParamType, cli, get_context, pass_context, Context
|
from toot.cli import InstanceParamType, cli, get_context, pass_context, Context, json_option
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from toot.cli.validators import validate_instance
|
from toot.cli.validators import validate_instance
|
||||||
|
|
||||||
from toot.entities import Notification, Status, from_dict
|
from toot.entities import Notification, Status, from_dict
|
||||||
from toot.output import print_notifications, print_timeline
|
from toot.output import print_notifications, print_timeline, print_warning
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@ -123,12 +123,14 @@ def bookmarks(
|
||||||
"--mentions", "-m", is_flag=True,
|
"--mentions", "-m", is_flag=True,
|
||||||
help="Show only mentions"
|
help="Show only mentions"
|
||||||
)
|
)
|
||||||
|
@json_option
|
||||||
@pass_context
|
@pass_context
|
||||||
def notifications(
|
def notifications(
|
||||||
ctx: Context,
|
ctx: Context,
|
||||||
clear: bool,
|
clear: bool,
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
mentions: int,
|
mentions: bool,
|
||||||
|
json: bool,
|
||||||
):
|
):
|
||||||
"""Show notifications"""
|
"""Show notifications"""
|
||||||
if clear:
|
if clear:
|
||||||
|
@ -142,17 +144,22 @@ def notifications(
|
||||||
# https://docs.joinmastodon.org/methods/notifications/
|
# https://docs.joinmastodon.org/methods/notifications/
|
||||||
exclude = ["follow", "favourite", "reblog", "poll", "follow_request"]
|
exclude = ["follow", "favourite", "reblog", "poll", "follow_request"]
|
||||||
|
|
||||||
notifications = api.get_notifications(ctx.app, ctx.user, exclude_types=exclude)
|
response = api.get_notifications(ctx.app, ctx.user, exclude_types=exclude)
|
||||||
|
|
||||||
if not notifications:
|
if json:
|
||||||
click.echo("You have no notifications")
|
if reverse:
|
||||||
|
print_warning("--reverse is not supported alongside --json, ignoring")
|
||||||
|
click.echo(response.text)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
notifications = [from_dict(Notification, n) for n in response.json()]
|
||||||
if reverse:
|
if reverse:
|
||||||
notifications = reversed(notifications)
|
notifications = reversed(notifications)
|
||||||
|
|
||||||
notifications = [from_dict(Notification, n) for n in notifications]
|
if notifications:
|
||||||
print_notifications(notifications)
|
print_notifications(notifications)
|
||||||
|
else:
|
||||||
|
click.echo("You have no notifications")
|
||||||
|
|
||||||
|
|
||||||
def _show_timeline(generator, reverse, once):
|
def _show_timeline(generator, reverse, once):
|
||||||
|
|
|
@ -281,7 +281,7 @@ def print_notification(notification: Notification):
|
||||||
print_status(notification.status)
|
print_status(notification.status)
|
||||||
|
|
||||||
|
|
||||||
def print_notifications(notifications: t.List[Notification]):
|
def print_notifications(notifications: t.Iterable[Notification]):
|
||||||
for notification in notifications:
|
for notification in notifications:
|
||||||
if notification.type not in ["pleroma:emoji_reaction"]:
|
if notification.type not in ["pleroma:emoji_reaction"]:
|
||||||
print_divider()
|
print_divider()
|
||||||
|
|
Ładowanie…
Reference in New Issue