Fix importing Session using wrong package

This commit is contained in:
Ben 2024-01-30 18:28:35 +01:00
parent 3dcf0f4430
commit 35cadf318a
Signed by: ben
GPG key ID: 1353F41CF1CFF2D3
3 changed files with 9 additions and 9 deletions

View file

@ -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:

View file

@ -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

View file

@ -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)