From 07a4d44389087fdc8ea68e4756c166919943fc3d Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Wed, 20 Nov 2024 07:39:49 +0100 Subject: [PATCH] dsc sell query discogs/db with arbitrary args - Former release_id arg now --release_id (overrides search) - Any number of arguments is passed as space delimited string to ctrl.collection.search(), which handles searching online or in DB. - Tiny fix in error handling/reporting success when listed. --- discodos/cmd23/sell.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/discodos/cmd23/sell.py b/discodos/cmd23/sell.py index 93aefa3..8a2a0cb 100644 --- a/discodos/cmd23/sell.py +++ b/discodos/cmd23/sell.py @@ -7,7 +7,12 @@ @click.command(name='sell') @click.pass_obj -@click.argument("release_id", type=int) +@click.argument("query", nargs=-1) +@click.option( + "--id", "-i", "release_id", + type=int, + help="Omit search by passing a release ID with this option." +) @click.option( "-c", "--condition", type=click.Choice(["M", "NM", "VG+", "VG", "G+", "G", "F", "P"], @@ -63,7 +68,7 @@ prompt="Private comments", help="Private comments about the listing." ) -def sell_cmd(helper, release_id, condition, sleeve_condition, price, status, +def sell_cmd(helper, query, release_id, condition, sleeve_condition, price, status, location, allow_offers, comments, private_comments): """ List a record for sale on Discogs. @@ -87,6 +92,11 @@ def update_user_interaction_helper(user): log.warning("Online mode is required to list a record for sale.") return + if not release_id: + found_release = coll_ctrl.search_release(" ".join(query)) + # search_release exits program, not required to handle here. + release_id = found_release["id"] + if not price: suggested_price = coll_ctrl.collection.fetch_price_suggestion( release_id, condition @@ -106,7 +116,7 @@ def update_user_interaction_helper(user): price = click.prompt("Price", type=float) log.info(f"Attempting to list record {release_id} for sale.") - coll_ctrl.collection.list_for_sale( + listing_successful = coll_ctrl.collection.list_for_sale( release_id=release_id, condition=condition, sleeve_condition=sleeve_condition, @@ -117,4 +127,5 @@ def update_user_interaction_helper(user): comments=comments, private_comments=private_comments ) - coll_ctrl.cli.p("Listed for sale.") + if listing_successful: + coll_ctrl.cli.p("Listed for sale.")