searcherator 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- searcherator-0.0.1/PKG-INFO +113 -0
- searcherator-0.0.1/README.md +97 -0
- searcherator-0.0.1/pyproject.toml +32 -0
- searcherator-0.0.1/searcherator/__init__.py +1 -0
- searcherator-0.0.1/searcherator/searcherator.py +71 -0
- searcherator-0.0.1/searcherator.egg-info/PKG-INFO +113 -0
- searcherator-0.0.1/searcherator.egg-info/SOURCES.txt +9 -0
- searcherator-0.0.1/searcherator.egg-info/dependency_links.txt +1 -0
- searcherator-0.0.1/searcherator.egg-info/requires.txt +3 -0
- searcherator-0.0.1/searcherator.egg-info/top_level.txt +1 -0
- searcherator-0.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: searcherator
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python package for performing cached web searches using the Brave Search API
|
|
5
|
+
Author-email: Arved Klöhn <arved.kloehn@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Redundando/searcherator
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/Redundando/searcherator/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: cacherator
|
|
14
|
+
Requires-Dist: logorator
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
|
|
17
|
+
# Searcherator
|
|
18
|
+
|
|
19
|
+
Searcherator is a Python package that provides a convenient way to perform web searches using the Brave Search API with built-in caching capabilities.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install searcherator
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Requirements
|
|
28
|
+
|
|
29
|
+
- Python 3.8+
|
|
30
|
+
- Brave Search API key
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from searcherator import Searcherator
|
|
36
|
+
import asyncio
|
|
37
|
+
|
|
38
|
+
async def main():
|
|
39
|
+
# Basic search in English (US)
|
|
40
|
+
search = Searcherator("Python programming language")
|
|
41
|
+
|
|
42
|
+
# Get URLs from search results
|
|
43
|
+
urls = await search.urls()
|
|
44
|
+
print(urls)
|
|
45
|
+
|
|
46
|
+
# German search with more results
|
|
47
|
+
german_search = Searcherator(
|
|
48
|
+
"Zusammenfassung Buch 'Demian' von 'Hermann Hesse'",
|
|
49
|
+
language="de",
|
|
50
|
+
country="de",
|
|
51
|
+
num_results=10
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Print full search results
|
|
55
|
+
await german_search.print()
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
asyncio.run(main())
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API Reference
|
|
62
|
+
|
|
63
|
+
### Searcherator
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
Searcherator(
|
|
67
|
+
search_term: str = "",
|
|
68
|
+
num_results: int = 5,
|
|
69
|
+
country: str | None = "us",
|
|
70
|
+
language: str | None = "en",
|
|
71
|
+
api_key: str | None = None,
|
|
72
|
+
clear_cache: bool = False,
|
|
73
|
+
ttl: int = 7
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Parameters
|
|
78
|
+
|
|
79
|
+
- `search_term`: The query string to search for
|
|
80
|
+
- `num_results`: Maximum number of results to return (default: 5)
|
|
81
|
+
- `country`: Country code for search results (default: "us")
|
|
82
|
+
- `language`: Language code for search results (default: "en")
|
|
83
|
+
- `api_key`: Brave Search API key (default: None, will try to use BRAVE_API_KEY environment variable)
|
|
84
|
+
- `clear_cache`: Whether to clear existing cached results (default: False)
|
|
85
|
+
- `ttl`: Time-to-live for cached results in days (default: 7)
|
|
86
|
+
|
|
87
|
+
#### Methods
|
|
88
|
+
|
|
89
|
+
- `async urls() -> list[str]`: Returns a list of URLs from the search results
|
|
90
|
+
- `async search_result() -> dict`: Returns the full search results as a dictionary
|
|
91
|
+
- `async print()`: Prints the full search results in a formatted way
|
|
92
|
+
|
|
93
|
+
## Authentication
|
|
94
|
+
|
|
95
|
+
Set your Brave Search API key as an environment variable:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
export BRAVE_API_KEY="your-api-key-here"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Alternatively, provide the API key directly when initializing the Searcherator:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
search = Searcherator("My search term", api_key="your-api-key-here")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT License
|
|
110
|
+
|
|
111
|
+
## Author
|
|
112
|
+
|
|
113
|
+
Arved Klöhn - [GitHub](https://github.com/Redundando/)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Searcherator
|
|
2
|
+
|
|
3
|
+
Searcherator is a Python package that provides a convenient way to perform web searches using the Brave Search API with built-in caching capabilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install searcherator
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Python 3.8+
|
|
14
|
+
- Brave Search API key
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from searcherator import Searcherator
|
|
20
|
+
import asyncio
|
|
21
|
+
|
|
22
|
+
async def main():
|
|
23
|
+
# Basic search in English (US)
|
|
24
|
+
search = Searcherator("Python programming language")
|
|
25
|
+
|
|
26
|
+
# Get URLs from search results
|
|
27
|
+
urls = await search.urls()
|
|
28
|
+
print(urls)
|
|
29
|
+
|
|
30
|
+
# German search with more results
|
|
31
|
+
german_search = Searcherator(
|
|
32
|
+
"Zusammenfassung Buch 'Demian' von 'Hermann Hesse'",
|
|
33
|
+
language="de",
|
|
34
|
+
country="de",
|
|
35
|
+
num_results=10
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# Print full search results
|
|
39
|
+
await german_search.print()
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
asyncio.run(main())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API Reference
|
|
46
|
+
|
|
47
|
+
### Searcherator
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
Searcherator(
|
|
51
|
+
search_term: str = "",
|
|
52
|
+
num_results: int = 5,
|
|
53
|
+
country: str | None = "us",
|
|
54
|
+
language: str | None = "en",
|
|
55
|
+
api_key: str | None = None,
|
|
56
|
+
clear_cache: bool = False,
|
|
57
|
+
ttl: int = 7
|
|
58
|
+
)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Parameters
|
|
62
|
+
|
|
63
|
+
- `search_term`: The query string to search for
|
|
64
|
+
- `num_results`: Maximum number of results to return (default: 5)
|
|
65
|
+
- `country`: Country code for search results (default: "us")
|
|
66
|
+
- `language`: Language code for search results (default: "en")
|
|
67
|
+
- `api_key`: Brave Search API key (default: None, will try to use BRAVE_API_KEY environment variable)
|
|
68
|
+
- `clear_cache`: Whether to clear existing cached results (default: False)
|
|
69
|
+
- `ttl`: Time-to-live for cached results in days (default: 7)
|
|
70
|
+
|
|
71
|
+
#### Methods
|
|
72
|
+
|
|
73
|
+
- `async urls() -> list[str]`: Returns a list of URLs from the search results
|
|
74
|
+
- `async search_result() -> dict`: Returns the full search results as a dictionary
|
|
75
|
+
- `async print()`: Prints the full search results in a formatted way
|
|
76
|
+
|
|
77
|
+
## Authentication
|
|
78
|
+
|
|
79
|
+
Set your Brave Search API key as an environment variable:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
export BRAVE_API_KEY="your-api-key-here"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Alternatively, provide the API key directly when initializing the Searcherator:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
search = Searcherator("My search term", api_key="your-api-key-here")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT License
|
|
94
|
+
|
|
95
|
+
## Author
|
|
96
|
+
|
|
97
|
+
Arved Klöhn - [GitHub](https://github.com/Redundando/)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "searcherator"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Arved Klöhn", email="arved.kloehn@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "A Python package for performing cached web searches using the Brave Search API"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"cacherator",
|
|
21
|
+
"logorator",
|
|
22
|
+
"aiohttp",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.setuptools]
|
|
26
|
+
packages = [
|
|
27
|
+
"searcherator"
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
"Homepage" = "https://github.com/Redundando/searcherator"
|
|
32
|
+
"Bug Tracker" = "https://github.com/Redundando/searcherator/issues"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .searcherator import Searcherator
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import os
|
|
3
|
+
from pprint import pprint
|
|
4
|
+
|
|
5
|
+
import aiohttp
|
|
6
|
+
from cacherator import Cached, JSONCache
|
|
7
|
+
from logorator import Logger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Searcherator(JSONCache):
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
search_term="",
|
|
15
|
+
num_results: int = 5,
|
|
16
|
+
country: str | None = "us",
|
|
17
|
+
language: str | None = "en",
|
|
18
|
+
api_key: str | None = None,
|
|
19
|
+
clear_cache=False,
|
|
20
|
+
ttl=7):
|
|
21
|
+
self.api_key = api_key
|
|
22
|
+
if api_key is None:
|
|
23
|
+
try:
|
|
24
|
+
self.api_key = os.getenv("BRAVE_API_KEY")
|
|
25
|
+
except KeyError:
|
|
26
|
+
self.api_key = None
|
|
27
|
+
self._search_results = None
|
|
28
|
+
self._urls = None
|
|
29
|
+
super().__init__(data_id=f"{search_term} ({language} {country} {num_results})", directory="data/search", clear_cache=clear_cache, ttl=ttl)
|
|
30
|
+
self.search_term = search_term
|
|
31
|
+
self.num_results = num_results
|
|
32
|
+
self.language = language
|
|
33
|
+
self.country = country
|
|
34
|
+
|
|
35
|
+
def __str__(self):
|
|
36
|
+
return f"Search: {self.search_term}"
|
|
37
|
+
|
|
38
|
+
def __repr__(self):
|
|
39
|
+
return self.__str__()
|
|
40
|
+
|
|
41
|
+
@Logger()
|
|
42
|
+
async def async_search(self):
|
|
43
|
+
if self._search_results is None:
|
|
44
|
+
url = 'https://api.search.brave.com/res/v1/web/search'
|
|
45
|
+
headers = {'Accept': 'application/json', 'X-Subscription-Token': self.api_key, }
|
|
46
|
+
params = {'q': self.search_term, 'count': self.num_results, 'country': self.country, 'search_lang': self.language, 'spellcheck': 'false'}
|
|
47
|
+
async with aiohttp.ClientSession() as session:
|
|
48
|
+
async with session.get(url, headers=headers, params=params) as response:
|
|
49
|
+
if response.status == 200:
|
|
50
|
+
self._search_results = await response.json()
|
|
51
|
+
else:
|
|
52
|
+
Logger.note(f"Error: {response.status} - {await response.text()}")
|
|
53
|
+
return self._search_results
|
|
54
|
+
|
|
55
|
+
async def urls(self):
|
|
56
|
+
if self._urls is None:
|
|
57
|
+
self._urls = []
|
|
58
|
+
search_results = await self.search_result()
|
|
59
|
+
for result in search_results.get("web", {}).get("results", []):
|
|
60
|
+
self._urls.append(result["url"])
|
|
61
|
+
return self._urls
|
|
62
|
+
|
|
63
|
+
async def search_result(self):
|
|
64
|
+
if self._search_results is None:
|
|
65
|
+
self._search_results = await self.async_search()
|
|
66
|
+
return self._search_results
|
|
67
|
+
|
|
68
|
+
async def print(self):
|
|
69
|
+
pprint(await self.search_result(), width=200, indent=2)
|
|
70
|
+
|
|
71
|
+
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: searcherator
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python package for performing cached web searches using the Brave Search API
|
|
5
|
+
Author-email: Arved Klöhn <arved.kloehn@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Redundando/searcherator
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/Redundando/searcherator/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: cacherator
|
|
14
|
+
Requires-Dist: logorator
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
|
|
17
|
+
# Searcherator
|
|
18
|
+
|
|
19
|
+
Searcherator is a Python package that provides a convenient way to perform web searches using the Brave Search API with built-in caching capabilities.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install searcherator
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Requirements
|
|
28
|
+
|
|
29
|
+
- Python 3.8+
|
|
30
|
+
- Brave Search API key
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from searcherator import Searcherator
|
|
36
|
+
import asyncio
|
|
37
|
+
|
|
38
|
+
async def main():
|
|
39
|
+
# Basic search in English (US)
|
|
40
|
+
search = Searcherator("Python programming language")
|
|
41
|
+
|
|
42
|
+
# Get URLs from search results
|
|
43
|
+
urls = await search.urls()
|
|
44
|
+
print(urls)
|
|
45
|
+
|
|
46
|
+
# German search with more results
|
|
47
|
+
german_search = Searcherator(
|
|
48
|
+
"Zusammenfassung Buch 'Demian' von 'Hermann Hesse'",
|
|
49
|
+
language="de",
|
|
50
|
+
country="de",
|
|
51
|
+
num_results=10
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Print full search results
|
|
55
|
+
await german_search.print()
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
asyncio.run(main())
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API Reference
|
|
62
|
+
|
|
63
|
+
### Searcherator
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
Searcherator(
|
|
67
|
+
search_term: str = "",
|
|
68
|
+
num_results: int = 5,
|
|
69
|
+
country: str | None = "us",
|
|
70
|
+
language: str | None = "en",
|
|
71
|
+
api_key: str | None = None,
|
|
72
|
+
clear_cache: bool = False,
|
|
73
|
+
ttl: int = 7
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Parameters
|
|
78
|
+
|
|
79
|
+
- `search_term`: The query string to search for
|
|
80
|
+
- `num_results`: Maximum number of results to return (default: 5)
|
|
81
|
+
- `country`: Country code for search results (default: "us")
|
|
82
|
+
- `language`: Language code for search results (default: "en")
|
|
83
|
+
- `api_key`: Brave Search API key (default: None, will try to use BRAVE_API_KEY environment variable)
|
|
84
|
+
- `clear_cache`: Whether to clear existing cached results (default: False)
|
|
85
|
+
- `ttl`: Time-to-live for cached results in days (default: 7)
|
|
86
|
+
|
|
87
|
+
#### Methods
|
|
88
|
+
|
|
89
|
+
- `async urls() -> list[str]`: Returns a list of URLs from the search results
|
|
90
|
+
- `async search_result() -> dict`: Returns the full search results as a dictionary
|
|
91
|
+
- `async print()`: Prints the full search results in a formatted way
|
|
92
|
+
|
|
93
|
+
## Authentication
|
|
94
|
+
|
|
95
|
+
Set your Brave Search API key as an environment variable:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
export BRAVE_API_KEY="your-api-key-here"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Alternatively, provide the API key directly when initializing the Searcherator:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
search = Searcherator("My search term", api_key="your-api-key-here")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT License
|
|
110
|
+
|
|
111
|
+
## Author
|
|
112
|
+
|
|
113
|
+
Arved Klöhn - [GitHub](https://github.com/Redundando/)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
searcherator/__init__.py
|
|
4
|
+
searcherator/searcherator.py
|
|
5
|
+
searcherator.egg-info/PKG-INFO
|
|
6
|
+
searcherator.egg-info/SOURCES.txt
|
|
7
|
+
searcherator.egg-info/dependency_links.txt
|
|
8
|
+
searcherator.egg-info/requires.txt
|
|
9
|
+
searcherator.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
searcherator
|