Fix importing Session using wrong package
This commit is contained in:
parent
3dcf0f4430
commit
35cadf318a
|
@ -1,8 +1,8 @@
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
|
|
||||||
import sqlalchemy
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session as AlchemySession
|
||||||
|
|
||||||
from .models import Resource, Recipe, ResourceFlow
|
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()
|
matching_resources = session.scalars(Resource.by_label(resource_label)).all()
|
||||||
if len(matching_resources) == 0:
|
if len(matching_resources) == 0:
|
||||||
print("Could not find existing resources matching the search string.. starting wiki search")
|
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
|
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)
|
stmt = select(Recipe).join(Recipe.results).filter(ResourceFlow.resource_id == resource.id)
|
||||||
recipes = session.scalars(stmt).all()
|
recipes = session.scalars(stmt).all()
|
||||||
if len(recipes) == 0:
|
if len(recipes) == 0:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
import sqlalchemy
|
from sqlalchemy.orm import Session as AlchemySession
|
||||||
|
|
||||||
from .models import Resource
|
from .models import Resource
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ from .models import Resource
|
||||||
class RecipeProvider(abc.ABC):
|
class RecipeProvider(abc.ABC):
|
||||||
|
|
||||||
@abc.abstractmethod
|
@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
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def update_resource_recipes(self, session: sqlalchemy.Session, resource: Resource):
|
def update_resource_recipes(self, session: AlchemySession, resource: Resource):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -3,10 +3,10 @@ from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
import sqlalchemy
|
|
||||||
from selenium.webdriver import Firefox
|
from selenium.webdriver import Firefox
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.firefox.options import Options
|
from selenium.webdriver.firefox.options import Options
|
||||||
|
from sqlalchemy.orm import Session as AlchemySession
|
||||||
|
|
||||||
from .models import Resource, ResourceFlow, Factory, Recipe
|
from .models import Resource, ResourceFlow, Factory, Recipe
|
||||||
from .provider import RecipeProvider
|
from .provider import RecipeProvider
|
||||||
|
@ -44,7 +44,7 @@ class SatisfactoryPlus(RecipeProvider, AbstractContextManager):
|
||||||
def __exit__(self, __exc_type, __exc_value, __traceback):
|
def __exit__(self, __exc_type, __exc_value, __traceback):
|
||||||
self._browser_cleanup()
|
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 = self._init_browser()
|
||||||
browser.get("https://wiki.kyrium.space/")
|
browser.get("https://wiki.kyrium.space/")
|
||||||
search_bar = browser.find_element(By.CSS_SELECTOR, "nav input[placeholder='Search for an item...']")
|
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"))
|
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
|
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"
|
assert resource.wiki_url, "Resource wiki url not set"
|
||||||
browser = self._init_browser()
|
browser = self._init_browser()
|
||||||
browser.get(resource.wiki_url)
|
browser.get(resource.wiki_url)
|
||||||
|
|
Loading…
Reference in a new issue