Skip to content

Commit 0022667

Browse files
committed
add command edit-subscription
1 parent 80c2a94 commit 0022667

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

inoreader/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,5 +586,47 @@ def fetch_starred(folder, tags, outfile, outdir, limit, save_image, out_format):
586586
LOGGER.info("fetched %d articles and saved them in %s", fetched_count, outdir)
587587

588588

589+
@main.command("edit-subscription")
590+
@click.option("-a", "--action",
591+
required=True,
592+
type=click.Choice(['follow', 'unfollow', 'rename', 'add-folder', 'remove-folder']),
593+
help="")
594+
@click.option("-i", "--stream-id", required=True, help='Stream ID which you want to fetch')
595+
@click.option("-n", "--name", help='The name of subscription, for action follow/rename(required)')
596+
@click.option("-f", "--folder", help='Folder which subscription belong to')
597+
@catch_error
598+
def edit_subscriptions(action, stream_id, name, folder):
599+
"""Get your subscriptions"""
600+
edit_action = action
601+
if action in ('rename', 'add-folder', 'remove-folder'):
602+
edit_action = 'edit'
603+
if action == 'rename' and not name:
604+
click.secho("`name` is required for action `rename`!", fg="red")
605+
return -1
606+
elif action in ('add-folder', 'remove_starred') and not folder:
607+
click.secho(f"`folder` is required for action `{action}`", fg="red")
608+
return -1
609+
610+
client = get_client()
611+
stream_id = 'feed/' + stream_id if not stream_id.startswith('feed/') else stream_id
612+
if folder and not folder.startswith('user/-/label/'):
613+
folder = client.GENERAL_TAG_TEMPLATE.format(folder)
614+
615+
add_folder = folder if action in ('follow', 'add-folder') else None
616+
remove_folder = folder if action == 'remove-folder' else None
617+
try:
618+
response = client.edit_subscription(
619+
stream_id,
620+
edit_action,
621+
title=name,
622+
add_folder=add_folder,
623+
remove_folder=remove_folder
624+
)
625+
click.secho(response, fg="green")
626+
except Exception as exception:
627+
print("Error:", str(exception))
628+
return -1
629+
630+
589631
if __name__ == '__main__':
590632
main()

0 commit comments

Comments
 (0)