diff --git a/internet_ml/tools/NLP/data/internet.py b/internet_ml/tools/NLP/data/internet.py index dec77e8..8a67b7c 100644 --- a/internet_ml/tools/NLP/data/internet.py +++ b/internet_ml/tools/NLP/data/internet.py @@ -36,15 +36,20 @@ def google_urls(query: str, links: list[str]) -> list[str]: response = requests.get( "https://www.googleapis.com/customsearch/v1", params={ - "key": os.environ["API_KEY"], + "key": config.GOOGLE_API_KEY, "q": query, - "cx": os.environ["SEARCH_ENGINE_ID"], + "cx": config.GOOGLE_SEARCH_ENGINE_ID, }, ) results = response.json()["items"] # Print the search results + num_of_res: int = ( + 5 if config.CONF_MODE == "speed" else (20 if config.CONF_MODE else 10) + ) for result in results: links.append(result["link"]) + if len(links) == num_of_res: + break return links diff --git a/internet_ml/utils/config.py b/internet_ml/utils/config.py index c87dd2c..1a0dced 100644 --- a/internet_ml/utils/config.py +++ b/internet_ml/utils/config.py @@ -7,12 +7,21 @@ logging.basicConfig( format="%(name)s - %(levelname)s - %(message)s", ) +GOOGLE_API_KEY: str = "" +GOOGLE_SEARCH_ENGINE_ID: str = "" + # Global NLP_CONF_DEBUG: bool = True # NLP NLP_CONF_MODE: str = "default" +def API_CONFIG(_GOOGLE_API_KEY: str = "", _GOOGLE_SEARCH_ENGINE_ID: str = "") -> None: + global GOOGLE_SEARCH_ENGINE_ID, GOOGLE_API_KEY + GOOGLE_API_KEY = _GOOGLE_API_KEY + GOOGLE_SEARCH_ENGINE_ID = _GOOGLE_SEARCH_ENGINE_ID + + def NLP_config(mode: str = "default", debug: bool = True) -> None: global conf_MODE, conf_DEBUG NLP_CONF_DEBUG = debug diff --git a/pyproject.toml b/pyproject.toml index 18ed0dc..557cd68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "internet_ml" -version = "0.1.1" +version = "0.1.2" description = "Internet-ML: Allowing ML to connect to the internet" readme = "./.github/README.md" authors = ["Thamognya Kodi "] diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..69c3e11 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +poetry publish --build --username $PYPI_USERNAME --password $PYPI_PASSWORD