Add ignore factories option for craft bench and fluid packer
This commit is contained in:
parent
45b05167ee
commit
2cf6e2e0a2
|
@ -13,8 +13,9 @@ from ..helper import click_prompt
|
|||
@click.command()
|
||||
@click.option("--debug", is_flag=True)
|
||||
@click.option("--refetch", is_flag=True)
|
||||
@click.option("--ignore-factories", type=list[str], default=["A.I. Fluid Packer", "Craft Bench"])
|
||||
@click.argument("search")
|
||||
def main(debug: bool, refetch: bool, search: str):
|
||||
def main(debug: bool, refetch: bool, ignore_factories: list[str], search: str):
|
||||
engine = create_engine("sqlite:///file.db", echo=debug)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
if not search:
|
||||
|
@ -25,7 +26,7 @@ def main(debug: bool, refetch: bool, search: str):
|
|||
resource = chose_resource(session=session, resource_label=search, prompt=click_prompt).result()
|
||||
exists_in_db = resource is not None
|
||||
|
||||
with SatisfactoryPlus(debug=debug) as data_provider:
|
||||
with SatisfactoryPlus(ignore_factories=ignore_factories, debug=debug) as data_provider:
|
||||
if resource is None:
|
||||
ret = data_provider.search_for_resource(session=session, search=search)
|
||||
if ret is None:
|
||||
|
|
|
@ -15,9 +15,13 @@ from ..helper import click_prompt
|
|||
|
||||
class SatisfactoryPlus(RecipeProvider, AbstractContextManager):
|
||||
_browser: Optional[Firefox] = None
|
||||
ignore_factories: list[str] = []
|
||||
|
||||
def __init__(self, debug: bool = False):
|
||||
def __init__(self, ignore_factories: list[str] = None, debug: bool = False):
|
||||
super().__init__()
|
||||
if ignore_factories:
|
||||
for factory in ignore_factories:
|
||||
self.ignore_factories.append(factory.casefold())
|
||||
self.debug = debug
|
||||
|
||||
def _init_browser(self) -> Firefox:
|
||||
|
@ -109,6 +113,9 @@ class SatisfactoryPlus(RecipeProvider, AbstractContextManager):
|
|||
factory_label = factory_html_elem.text.strip()
|
||||
assert factory_label, "factory label is missing (a[text])"
|
||||
|
||||
if factory_label.casefold() in self.ignore_factories:
|
||||
return
|
||||
|
||||
# re-use existing Factory or create new
|
||||
factory = session.scalars(Factory.by_label(factory_label)).one_or_none()
|
||||
if factory is None:
|
||||
|
@ -117,6 +124,9 @@ class SatisfactoryPlus(RecipeProvider, AbstractContextManager):
|
|||
factory = Factory(label=factory_label, uri=self._normalize_url(href=factory_href))
|
||||
session.add(factory)
|
||||
recipe_factories.append(factory)
|
||||
if not recipe_factories:
|
||||
# ignore recipe when no applicable factories exist
|
||||
return
|
||||
|
||||
def find_or_create_resource(resource_label: str, resource_uri_getter: Callable) -> Resource:
|
||||
db_resource = session.scalars(Resource.by_label(resource_label)).one_or_none()
|
||||
|
|
Loading…
Reference in a new issue