Skip to content

Commit

Permalink
feat: improve API gateway lifecycle management and update documentation
Browse files Browse the repository at this point in the history
This commit introduces the following changes:
- Added initialization and shutdown methods for the API gateway lifecycle.
- Improved the README with better examples and instructions for initializing and shutting down the API gateway.
- Introduced user agent rotation in search requests for better reliability.
- Updated search logic to provide more structured and maintainable results handling.
- Enhanced the novexity_check script with better error handling and field validation.

Motivation:
Opening and closing API gateways within the search can lead to performance overhead during frequent searches. This change allows the user to manage the lifecycle of the API gateway explicitly, improving scalability.

Additional Changes:
- Added `venv` to .gitignore.
- Bumped package version from 1.0.5 to 1.0.6.
- Updated dependencies in `setup.cfg` to include `python-dotenv`.

BREAKING CHANGE:
Users must now explicitly call `NovexitySearch.init_gateway()` before initiating searches and `NovexitySearch.shutdown_gateway()` to clean up resources.
  • Loading branch information
NorkzYT committed Dec 10, 2024
1 parent 65ac8af commit 865eb23
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 190 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Novexity.egg-info

# Cache
__pycache__
venv

# Environment variables
.env
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ Example usage:

```python
import os
import json
from dotenv import load_dotenv
from novexity import NovexitySearch, configure

load_dotenv()

AWS_ACCESS_KEY_ID = os.getenv('GOOGLE_SEARCH_AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('GOOGLE_SEARCH_AWS_SECRET_ACCESS_KEY')
configure(aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
AWS_ACCESS_KEY_ID = os.getenv("GOOGLE_SEARCH_AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("GOOGLE_SEARCH_AWS_SECRET_ACCESS_KEY")
configure(
aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY
)

params = {
"q": "Minecraft",
"country": "fr",
"lang": "fr"
}
# Initialize API Gateway
NovexitySearch.init_gateway()

# Initialize NovexitySearch with the parameters
novexity_search = NovexitySearch(params)
params = {"q": "Minecraft", "country": "fr", "lang": "fr"}

# Get the search results
novexity, returned_gateway = novexity_search.get_dict()
# Perform search
novexity_search = NovexitySearch(params)
search_results = novexity_search.get_dict()

# Save the results to search.json
with open("google-search.json", "w", encoding="utf-8") as file:
file.write(novexity)
file.write(json.dumps(search_results, indent=4))

# Shut down the gateways
returned_gateway.shutdown()
# Shut down the API Gateway
NovexitySearch.shutdown_gateway()
```

⚠️ Remember: If gateways are not shut down via the `shutdown()` method, you may incur charges.
Expand Down Expand Up @@ -167,7 +167,7 @@ To make your search more tailored, Novexity supports various parameters that you

- `lang`: Two-letter language code for Google search (e.g., en for English, es for Spanish, or fr for French). Refer to [Google languages](./static/json/google-languages.json) for all available languages. Defaults to English ("en") if not specified.

- `lang_restrict`: Restricts search results to specific languages. Refer to [Google languages](./static/json/google-lr-languages.json) for all available languages.
- `lang_restrict`: Restricts search results to specific languages. Refer to [Google languages](./static/json/google-lr-languages.json) for all available languages.

- `location`: Google encoded location you want to use for the search. Note: Using `uule` requires a special value format (Google's encrypted location format).

Expand Down
Loading

0 comments on commit 865eb23

Please sign in to comment.