From 35cadf318a316a3270140bb6d7ff77c61f76c11c Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Tue, 30 Jan 2024 18:28:35 +0100 Subject: [PATCH] Fix importing Session using wrong package --- factorygame/data/common.py | 6 +++--- factorygame/data/provider.py | 6 +++--- factorygame/data/sfp.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/factorygame/data/common.py b/factorygame/data/common.py index 9a4b518..0a9ce49 100644 --- a/factorygame/data/common.py +++ b/factorygame/data/common.py @@ -1,8 +1,8 @@ from datetime import timedelta, datetime from typing import Callable, Optional -import sqlalchemy from sqlalchemy import select +from sqlalchemy.orm import Session as AlchemySession from .models import Resource, Recipe, ResourceFlow @@ -17,7 +17,7 @@ def resource_needs_update(resource: Resource | None, recipe_info_timeout: Option ) -def chose_resource(session: sqlalchemy.Session, resource_label: str, prompt: Callable) -> Resource | None: +def chose_resource(session: AlchemySession, resource_label: str, prompt: Callable) -> Resource | None: matching_resources = session.scalars(Resource.by_label(resource_label)).all() if len(matching_resources) == 0: print("Could not find existing resources matching the search string.. starting wiki search") @@ -32,7 +32,7 @@ def chose_resource(session: sqlalchemy.Session, resource_label: str, prompt: Cal return None -def chose_recipe(session: sqlalchemy.Session, resource: Resource, prompt: Callable) -> Recipe | None: +def chose_recipe(session: AlchemySession, resource: Resource, prompt: Callable) -> Recipe | None: stmt = select(Recipe).join(Recipe.results).filter(ResourceFlow.resource_id == resource.id) recipes = session.scalars(stmt).all() if len(recipes) == 0: diff --git a/factorygame/data/provider.py b/factorygame/data/provider.py index 4b7b135..5d9ca3c 100644 --- a/factorygame/data/provider.py +++ b/factorygame/data/provider.py @@ -1,6 +1,6 @@ import abc -import sqlalchemy +from sqlalchemy.orm import Session as AlchemySession from .models import Resource @@ -8,9 +8,9 @@ from .models import Resource class RecipeProvider(abc.ABC): @abc.abstractmethod - def search_for_resource(self, session: sqlalchemy.Session, search: str) -> tuple[Resource, bool]: + def search_for_resource(self, session: AlchemySession, search: str) -> tuple[Resource, bool]: pass @abc.abstractmethod - def update_resource_recipes(self, session: sqlalchemy.Session, resource: Resource): + def update_resource_recipes(self, session: AlchemySession, resource: Resource): pass diff --git a/factorygame/data/sfp.py b/factorygame/data/sfp.py index 9bee773..801d544 100644 --- a/factorygame/data/sfp.py +++ b/factorygame/data/sfp.py @@ -3,10 +3,10 @@ from datetime import datetime from typing import Optional from urllib.parse import urljoin -import sqlalchemy from selenium.webdriver import Firefox from selenium.webdriver.common.by import By from selenium.webdriver.firefox.options import Options +from sqlalchemy.orm import Session as AlchemySession from .models import Resource, ResourceFlow, Factory, Recipe from .provider import RecipeProvider @@ -44,7 +44,7 @@ class SatisfactoryPlus(RecipeProvider, AbstractContextManager): def __exit__(self, __exc_type, __exc_value, __traceback): self._browser_cleanup() - def search_for_resource(self, session: sqlalchemy.Session, search: str) -> tuple[Resource, bool] | None: + def search_for_resource(self, session: AlchemySession, search: str) -> tuple[Resource, bool] | None: browser = self._init_browser() browser.get("https://wiki.kyrium.space/") search_bar = browser.find_element(By.CSS_SELECTOR, "nav input[placeholder='Search for an item...']") @@ -81,7 +81,7 @@ class SatisfactoryPlus(RecipeProvider, AbstractContextManager): resource_fetch_url = self._normalize_url(href=link_html_elem.get_attribute("href")) return Resource(label=alt_resource_label, wiki_url=resource_fetch_url), False - def update_resource_recipes(self, session: sqlalchemy.Session, resource: Resource) -> Resource: + def update_resource_recipes(self, session: AlchemySession, resource: Resource) -> Resource: assert resource.wiki_url, "Resource wiki url not set" browser = self._init_browser() browser.get(resource.wiki_url)