From db51c2af32cebdae89e4fbd9e9978cfc20fa14d7 Mon Sep 17 00:00:00 2001 From: Dennis Priskorn Date: Fri, 14 Jul 2023 13:06:06 +0200 Subject: [PATCH] feat: Allow matching after unable to decide and manual check. --- src/models/enrich_hiking_trails.py | 2 +- src/models/trail_item.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/models/enrich_hiking_trails.py b/src/models/enrich_hiking_trails.py index 91b87be..609e3ae 100644 --- a/src/models/enrich_hiking_trails.py +++ b/src/models/enrich_hiking_trails.py @@ -107,7 +107,7 @@ def __lookup_in_waymarked_trails__(trail_item: TrailItem) -> None: f"Try looking at {trail_item.waymarked_hiking_trails_search_url} " f"and see if any fit with {trail_item.item.get_entity_url()}" ) - # TODO help the user match again + trail_item.try_matching_again() else: trail_item.osm_id_source = OsmIdSource.QUESTIONNAIRE trail_item.enrich_wikidata() diff --git a/src/models/trail_item.py b/src/models/trail_item.py index 9099a58..cda2d38 100644 --- a/src/models/trail_item.py +++ b/src/models/trail_item.py @@ -5,6 +5,7 @@ from urllib.parse import quote import pydash +import questionary import requests from dateutil.parser import parse # type: ignore from dateutil.tz import tzutc # type: ignore @@ -197,9 +198,8 @@ def __prepare_choices__(self): ) def __ask_question__(self) -> QuestionaryReturn: + """This presents a choice and returns""" # present the result to the user to choose from - import questionary - if not self.item: raise NoItemError() return_ = questionary.select( @@ -245,7 +245,6 @@ def fetch_and_lookup_from_waymarked_trails_and_present_choice_to_user(self): self.__get_item_details__() self.__lookup_label_on_waymarked_trails_and_ask_user_to_choose_a_match__() - # @validate_arguments() def enrich_wikidata(self): """We enrich Wikidata based on the choice of the user""" if self.osm_id_source == OsmIdSource.QUESTIONNAIRE: @@ -522,3 +521,15 @@ def __remove_not_found_in_osm_claim__(self): self.item.claims.remove(Property.OSM_RELATION_ID.value) except KeyError: logger.debug("No NOT_FOUND_IN found on this item to remove") + + def try_matching_again(self): + if self.questionary_return.could_not_decide is True: + result = questionary.select( + "Do you want to match again after manually ", + choices=[ + Choice(title="Yes", value=True), + Choice(title="No", value=False), + ], + ).ask() + if result: + self.questionary_return = self.__ask_question__()