@@ -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+
589631if __name__ == '__main__' :
590632 main ()
0 commit comments