An open source, non-profit web search engine
feat: Add configurable contact info to user-agent for responsible crawling
thiswillbeyourgithub (aider)0d7cfad57b77
diff --git a/docker-compose.yml b/docker-compose.ymlindex 4c3972a..db3d593 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -12,6 +12,9 @@ services:# Add your API key here:# - MWMBL_API_KEY=+ # REQUIRED: Contact info for website administrators+# Set value of ./mwmbl/crawler/env_vars.py- CRAWLER_WORKERS=10- CRAWLER_THREADS=20diff --git a/mwmbl/crawler/README.md b/mwmbl/crawler/README.mdindex 7f73429..b5259e6 100644--- a/mwmbl/crawler/README.md+++ b/mwmbl/crawler/README.md@@ -8,6 +8,7 @@ The crawler can be configured using the following environment variables:### Required Configuration- `MWMBL_API_KEY` - **Required** API key for submitting results to the Mwmbl search index+- `MWMBL_CONTACT_INFO` - **Required** Contact information for website administrators (email or website URL). This is included in the user-agent string so website administrators can contact you if there are issues with the crawler. Example: `[email protected]` or `https://your-mwmbl-instance.com`### Worker Configuration- `CRAWLER_WORKERS` (default: 10) - Number of separate operating system processes to spawn for crawling work (uses Python's multiprocessing.Process)diff --git a/mwmbl/crawler/env_vars.py b/mwmbl/crawler/env_vars.pyindex e010914..c12db01 100644--- a/mwmbl/crawler/env_vars.py+++ b/mwmbl/crawler/env_vars.py@@ -17,3 +17,14 @@ REDIS_URL = os.environ.get("REDIS_URL", "redis://127.0.0.1:6379")# API configurationMWMBL_API_KEY = os.environ["MWMBL_API_KEY"]++# Contact information configuration - required for responsible crawling+MWMBL_CONTACT_INFO = os.environ.get("MWMBL_CONTACT_INFO", "[email protected]")++# Validate that contact info has been set to a real value+if MWMBL_CONTACT_INFO == "[email protected]":+ raise ValueError(+ "MWMBL_CONTACT_INFO must be set to your email or website URL. "+ "This allows website administrators to contact you if needed. "+ "Example: [email protected] or https://your-mwmbl-instance.com"+ )diff --git a/mwmbl/crawler/retrieve.py b/mwmbl/crawler/retrieve.pyindex f4d7796..c4c76ba 100644--- a/mwmbl/crawler/retrieve.py+++ b/mwmbl/crawler/retrieve.py@@ -11,6 +11,7 @@ from mwmbl.justext import core, utilsfrom requests import ReadTimeoutfrom urllib3.exceptions import NewConnectionError, MaxRetryError+from mwmbl.crawler.env_vars import MWMBL_CONTACT_INFOfrom mwmbl.justext.core import html_to_domfrom mwmbl.justext.paragraph import Paragraph@@ -33,7 +34,7 @@ DEFAULT_ENCODING = 'utf8'DEFAULT_ENC_ERRORS = 'replace'MAX_SITE_URLS = 100CRAWLER_VERSION: str = "0.2.0"-USER_AGENT = f"mwmbl/{CRAWLER_VERSION} (https://mwmbl.org)"+USER_AGENT = f"mwmbl/{CRAWLER_VERSION} (https://github.com/mwmbl/mwmbl/ contact {MWMBL_CONTACT_INFO})"logger = getLogger(__name__)