Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

refactor: move hardcoded constants from env vars to respective files

thiswillbeyourgithub (aider)1e6b8748364c
diff --git a/mwmbl/crawl.py b/mwmbl/crawl.py
index 86284f0..b842bbe 100644
--- a/mwmbl/crawl.py
+++ b/mwmbl/crawl.py
@@ -34,10 +34,6 @@ from mwmbl.crawler.retrieve import crawl_batch, crawl_url
from mwmbl.crawler.batch import HashedBatch, Result, Results
from mwmbl.indexer.index_batches import index_batches, index_pages
-logger = logging.getLogger(__name__)
-FORMAT = "%(process)d:%(levelname)s:%(name)s:%(message)s"
-logging.basicConfig(level=logging.INFO, format=FORMAT)
-
API_KEY = os.environ["MWMBL_API_KEY"]
BATCH_QUEUE_KEY = "batch-queue"
diff --git a/mwmbl/crawler/README.md b/mwmbl/crawler/README.md
index 8d57292..7f73429 100644
--- a/mwmbl/crawler/README.md
+++ b/mwmbl/crawler/README.md
@@ -6,19 +6,8 @@ This module handles the distributed crawling functionality for Mwmbl. The crawle
The crawler can be configured using the following environment variables:
-### Crawling Assignment
-- `REASSIGN_MIN_HOURS` (default: 5) - Hours before a URL assigned to a client is reassigned if not crawled
-- `BATCH_SIZE` (default: 100) - Number of URLs in each crawling batch
-- `MAX_URLS_PER_TOP_DOMAIN` (default: 100) - Maximum URLs per top domain (for example wikipedia, reddit, etc)
-- `MAX_TOP_DOMAINS` (default: 500) - Maximum number of top domains to process
-- `MAX_OTHER_DOMAINS` (default: 50000) - Maximum number of other domains to process
-
-### URL Retrieval Configuration
-- `TIMEOUT_SECONDS` (default: 3) - Timeout for fetching individual URLs
-- `MAX_FETCH_SIZE` (default: 1048576) - Maximum size in bytes to fetch per URL (1MB)
-- `MAX_NEW_LINKS` (default: 50) - Maximum new links to extract from good content paragraphs
-- `MAX_EXTRA_LINKS` (default: 50) - Maximum extra links to extract from non-good paragraphs
-- `MAX_SITE_URLS` (default: 100) - TODO: clarify usage of this variable
+### Required Configuration
+- `MWMBL_API_KEY` - **Required** API key for submitting results to the Mwmbl search index
### 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.py
index aae2026..914f938 100644
--- a/mwmbl/crawler/env_vars.py
+++ b/mwmbl/crawler/env_vars.py
@@ -5,18 +5,18 @@ import os
# Client has one hour to crawl a URL that has been assigned to them, or it will be reassigned
-REASSIGN_MIN_HOURS = int(os.environ.get('REASSIGN_MIN_HOURS', '5'))
-BATCH_SIZE = int(os.environ.get('BATCH_SIZE', '100'))
-MAX_URLS_PER_TOP_DOMAIN = int(os.environ.get('MAX_URLS_PER_TOP_DOMAIN', '100'))
-MAX_TOP_DOMAINS = int(os.environ.get('MAX_TOP_DOMAINS', '500'))
-MAX_OTHER_DOMAINS = int(os.environ.get('MAX_OTHER_DOMAINS', '50000'))
+REASSIGN_MIN_HOURS = int(os.environ.get("REASSIGN_MIN_HOURS", "5"))
+BATCH_SIZE = int(os.environ.get("BATCH_SIZE", "100"))
+MAX_URLS_PER_TOP_DOMAIN = int(os.environ.get("MAX_URLS_PER_TOP_DOMAIN", "100"))
+MAX_TOP_DOMAINS = int(os.environ.get("MAX_TOP_DOMAINS", "500"))
+MAX_OTHER_DOMAINS = int(os.environ.get("MAX_OTHER_DOMAINS", "50000"))
# Retrieval configuration
-TIMEOUT_SECONDS = int(os.environ.get('TIMEOUT_SECONDS', '3'))
-MAX_FETCH_SIZE = int(os.environ.get('MAX_FETCH_SIZE', str(1024*1024)))
-MAX_NEW_LINKS = int(os.environ.get('MAX_NEW_LINKS', '50'))
-MAX_EXTRA_LINKS = int(os.environ.get('MAX_EXTRA_LINKS', '50'))
-MAX_SITE_URLS = int(os.environ.get('MAX_SITE_URLS', '100'))
+TIMEOUT_SECONDS = int(os.environ.get("TIMEOUT_SECONDS", "3"))
+MAX_FETCH_SIZE = int(os.environ.get("MAX_FETCH_SIZE", str(1024 * 1024)))
+MAX_NEW_LINKS = int(os.environ.get("MAX_NEW_LINKS", "50"))
+MAX_EXTRA_LINKS = int(os.environ.get("MAX_EXTRA_LINKS", "50"))
+MAX_SITE_URLS = int(os.environ.get("MAX_SITE_URLS", "100"))
# Crawler worker configuration
CRAWLER_WORKERS = int(os.environ.get('CRAWLER_WORKERS', '10'))
diff --git a/mwmbl/crawler/urls.py b/mwmbl/crawler/urls.py
index 123de2b..5f1558f 100644
--- a/mwmbl/crawler/urls.py
+++ b/mwmbl/crawler/urls.py
@@ -12,15 +12,16 @@ from django.conf import settings
from psycopg2.extras import execute_values
from pybloomfilter import BloomFilter
-from mwmbl.crawler.env_vars import (
- REASSIGN_MIN_HOURS,
- BATCH_SIZE,
- MAX_URLS_PER_TOP_DOMAIN,
- MAX_TOP_DOMAINS,
- MAX_OTHER_DOMAINS,
-)
from mwmbl.utils import batch
+# URL database configuration constants
+# Client has one hour to crawl a URL that has been assigned to them, or it will be reassigned
+REASSIGN_MIN_HOURS = 5
+BATCH_SIZE = 100
+MAX_URLS_PER_TOP_DOMAIN = 100
+MAX_TOP_DOMAINS = 500
+MAX_OTHER_DOMAINS = 50000
+
logger = getLogger(__name__)