Skip to content

Commit 6e4dd81

Browse files
bidoubiwacurquiza
andauthored
Immutable settings (#22)
* Make setting immutable between each scrape * Validate that custom settings is a dictionary * Change value of custom settings in tests * lint * Removed unecessary try and catch * Update scraper/src/meilisearch_helper.py Co-authored-by: Clémentine Urquizar <[email protected]> Co-authored-by: Clémentine Urquizar <[email protected]>
1 parent 39faa3c commit 6e4dd81

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

scraper/src/config/config_validator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def validate(self):
2525
list):
2626
raise Exception('stop_urls should be list')
2727

28+
# Custom settings must be a dict
29+
if self.config.custom_settings and not isinstance(self.config.custom_settings,
30+
dict):
31+
raise Exception('custom_settings must be a dictionary')
32+
2833
if self.config.js_render and not isinstance(self.config.js_render,
2934
bool):
3035
raise Exception('js_render should be boolean')

scraper/src/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def run_config(config):
4040
config.app_id,
4141
config.api_key,
4242
config.index_uid,
43+
config.custom_settings
4344
)
4445

4546
root_module = 'src.' if __name__ == '__main__' else 'scraper.src.'

scraper/src/meilisearch_helper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ class MeiliSearchHelper:
101101
'acceptNewFields': False
102102
}
103103

104-
def __init__(self, host_url, api_key, index_uid):
104+
def __init__(self, host_url, api_key, index_uid, custom_settings):
105105
self.meilisearch_client = meilisearch.Client(host_url, api_key)
106106
self.__delete_and_create_index(index_uid)
107107
self.meilisearch_index = self.__delete_and_create_index(index_uid)
108-
self.meilisearch_index.update_settings(MeiliSearchHelper.SETTINGS)
108+
settings = {**MeiliSearchHelper.SETTINGS, **custom_settings}
109+
self.meilisearch_index.update_settings(settings)
109110

110111
def add_records(self, records, url, from_sitemap):
111112
"""Add new records to the index"""

scraper/src/tests/config_loader/abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def config(additional_config={}):
77
'allowed_domains': 'allowed_domains',
88
'api_key': 'api_key',
99
'app_id': 'app_id',
10-
'custom_settings': 'custom_settings',
10+
'custom_settings': {},
1111
'hash_strategy': 'hash_strategy',
1212
'index_uid': 'index_uid',
1313
'selectors': [],

0 commit comments

Comments
 (0)