Convert SerpAPI config to Manual config,
and saves the results as json files.
Parameters:
| Name |
Type |
Description |
Default |
manual_folder |
AnyPath
|
intermediate folder to hold the downloaded csv and manual config
|
required
|
Source code in sm_trendy/manual/config.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 | class SerpAPI2Manual:
"""Convert SerpAPI config to Manual config,
and saves the results as json files.
:param manual_folder: intermediate folder to hold the
downloaded csv and manual config
"""
def __init__(self, manual_folder: AnyPath):
if manual_folder.exists():
assert (
len(list(manual_folder.iterdir())) == 0
), "An empty folder is required"
self.manual_folder = manual_folder
def __call__(self, config_bundle: SerpAPIConfigBundle):
"""
convert `SerpAPIConfigBundle` to a bunch of folders
with manual config inside.
"""
for c in config_bundle:
manual_config = c.path_params.model_dump()
c_temp_path = c.path_params.path(parent_folder=self.manual_folder)
c_temp_path.mkdir(parents=True, exist_ok=True)
logger.debug(f'Writing to {c_temp_path / "manual.json"} ...')
with open(c_temp_path / "manual.json", "w") as fp:
json.dump(manual_config, fp)
|
__call__(config_bundle)
convert SerpAPIConfigBundle to a bunch of folders
with manual config inside.
Source code in sm_trendy/manual/config.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39 | def __call__(self, config_bundle: SerpAPIConfigBundle):
"""
convert `SerpAPIConfigBundle` to a bunch of folders
with manual config inside.
"""
for c in config_bundle:
manual_config = c.path_params.model_dump()
c_temp_path = c.path_params.path(parent_folder=self.manual_folder)
c_temp_path.mkdir(parents=True, exist_ok=True)
logger.debug(f'Writing to {c_temp_path / "manual.json"} ...')
with open(c_temp_path / "manual.json", "w") as fp:
json.dump(manual_config, fp)
|