thordata-sdk 0.5.0__py3-none-any.whl → 0.7.0__py3-none-any.whl

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.
thordata/parameters.py CHANGED
@@ -1,53 +1,53 @@
1
- # src/thordata/parameters.py
2
-
3
- from typing import Any, Dict
4
-
5
-
6
- def normalize_serp_params(engine: str, query: str, **kwargs) -> Dict[str, Any]:
7
- """
8
- Normalizes parameters across different search engines to ensure a unified API surface.
9
-
10
- Args:
11
- engine (str): The search engine to use (e.g., 'google', 'yandex').
12
- query (str): The search query string.
13
- **kwargs: Additional parameters to pass to the API.
14
-
15
- Returns:
16
- Dict[str, Any]: The constructed payload for the API request.
17
- """
18
- # 1. Base parameters
19
- payload = {
20
- "num": str(kwargs.get("num", 10)), # Default to 10 results
21
- "json": "1", # Force JSON response
22
- "engine": engine,
23
- }
24
-
25
- # 2. Handle Query Parameter Differences (Yandex uses 'text', others use 'q')
26
- if engine == "yandex":
27
- payload["text"] = query
28
- # Set default URL for Yandex if not provided
29
- if "url" not in kwargs:
30
- payload["url"] = "yandex.com"
31
- else:
32
- payload["q"] = query
33
-
34
- # 3. Handle Default URLs for other engines
35
- if "url" not in kwargs:
36
- defaults = {
37
- "google": "google.com",
38
- "bing": "bing.com",
39
- "duckduckgo": "duckduckgo.com",
40
- "baidu": "baidu.com",
41
- }
42
- if engine in defaults:
43
- payload["url"] = defaults[engine]
44
-
45
- # 4. Passthrough for all other user-provided arguments
46
- # This allows support for engine-specific parameters (e.g., tbm, uule, gl)
47
- # without explicitly defining them all.
48
- protected_keys = {"num", "engine", "q", "text"}
49
- for key, value in kwargs.items():
50
- if key not in protected_keys:
51
- payload[key] = value
52
-
53
- return payload
1
+ # src/thordata/parameters.py
2
+
3
+ from typing import Any, Dict
4
+
5
+
6
+ def normalize_serp_params(engine: str, query: str, **kwargs) -> Dict[str, Any]:
7
+ """
8
+ Normalizes parameters across different search engines to ensure a unified API surface.
9
+
10
+ Args:
11
+ engine (str): The search engine to use (e.g., 'google', 'yandex').
12
+ query (str): The search query string.
13
+ **kwargs: Additional parameters to pass to the API.
14
+
15
+ Returns:
16
+ Dict[str, Any]: The constructed payload for the API request.
17
+ """
18
+ # 1. Base parameters
19
+ payload = {
20
+ "num": str(kwargs.get("num", 10)), # Default to 10 results
21
+ "json": "1", # Force JSON response
22
+ "engine": engine,
23
+ }
24
+
25
+ # 2. Handle Query Parameter Differences (Yandex uses 'text', others use 'q')
26
+ if engine == "yandex":
27
+ payload["text"] = query
28
+ # Set default URL for Yandex if not provided
29
+ if "url" not in kwargs:
30
+ payload["url"] = "yandex.com"
31
+ else:
32
+ payload["q"] = query
33
+
34
+ # 3. Handle Default URLs for other engines
35
+ if "url" not in kwargs:
36
+ defaults = {
37
+ "google": "google.com",
38
+ "bing": "bing.com",
39
+ "duckduckgo": "duckduckgo.com",
40
+ "baidu": "baidu.com",
41
+ }
42
+ if engine in defaults:
43
+ payload["url"] = defaults[engine]
44
+
45
+ # 4. Passthrough for all other user-provided arguments
46
+ # This allows support for engine-specific parameters (e.g., tbm, uule, gl)
47
+ # without explicitly defining them all.
48
+ protected_keys = {"num", "engine", "q", "text"}
49
+ for key, value in kwargs.items():
50
+ if key not in protected_keys:
51
+ payload[key] = value
52
+
53
+ return payload