diff --git a/dailyreleases/stores/__init__.py b/dailyreleases/stores/__init__.py index 92410b0..21b7148 100644 --- a/dailyreleases/stores/__init__.py +++ b/dailyreleases/stores/__init__.py @@ -1,30 +1,13 @@ import logging import re -from typing import Dict, List -from urllib.error import HTTPError +from typing import Dict -from .. import cache -from ..config import CONFIG +from .web import web_search from ..stores import steam, gog logger = logging.getLogger(__name__) -def web_search(query: str) -> List[str]: - logger.debug("Searching Google for %s", query) - try: - r = cache.get("https://www.googleapis.com/customsearch/v1", params={ - "key": CONFIG["google"]["key"], - "cx": CONFIG["google"]["cx"], - "q": query - }) - return [result["link"] for result in r.json["items"]] - except (KeyError, HTTPError) as e: - logger.exception(e) - logger.warning("Google search failed (probably rate-limited)") - return [] - - def find_store_links(game_name: str) -> Dict[str, str]: links = {} for store, name in ((steam, "Steam"), (gog, "GOG")): diff --git a/dailyreleases/stores/web.py b/dailyreleases/stores/web.py new file mode 100644 index 0000000..1f88d7c --- /dev/null +++ b/dailyreleases/stores/web.py @@ -0,0 +1,24 @@ +import logging +from typing import List +from urllib.error import HTTPError + +from .. import cache +from ..config import CONFIG + +logger = logging.getLogger(__name__) + + +def web_search(query: str) -> List[str]: + logger.debug("Searching Google for %s", query) + try: + # disable rate-limiting since we have a proper API-key (unlike the other APIs we are using) + r = cache.get("https://www.googleapis.com/customsearch/v1", ratelimit=None, params={ + "key": CONFIG["google"]["key"], + "cx": CONFIG["google"]["cx"], + "q": query + }) + return [result["link"] for result in r.json["items"]] + except (KeyError, HTTPError) as e: + logger.exception(e) + logger.warning("Google search failed (probably rate-limited)") + return []