Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

fix: duplicate crawler version + better declaration

thiswillbeyourgithubcc4f5c2b6a38
diff --git a/mwmbl/crawl.py b/mwmbl/crawl.py
index 5f316b8..9b994ec 100644
--- a/mwmbl/crawl.py
+++ b/mwmbl/crawl.py
@@ -29,7 +29,7 @@ print("Mwmbl crawling statistics: https://mwmbl.org/stats")
django.setup()
from mwmbl.indexer.update_urls import record_urls_in_database
-from mwmbl.crawler.retrieve import crawl_batch, crawl_url
+from mwmbl.crawler.retrieve import crawl_batch, crawl_url, CRAWLER_VERSION
from mwmbl.crawler.batch import HashedBatch, Result, Results
from mwmbl.indexer.index_batches import index_batches, index_pages
@@ -38,7 +38,6 @@ FORMAT = "%(process)d:%(levelname)s:%(name)s:%(message)s"
logging.basicConfig(level=logging.INFO, format=FORMAT)
BATCH_QUEUE_KEY = "batch-queue"
-CRAWLER_VERSION: str = "0.2.0"
redis = Redis.from_url(
diff --git a/mwmbl/crawler/retrieve.py b/mwmbl/crawler/retrieve.py
index 4217bdb..f4d7796 100644
--- a/mwmbl/crawler/retrieve.py
+++ b/mwmbl/crawler/retrieve.py
@@ -15,7 +15,6 @@ from mwmbl.justext.core import html_to_dom
from mwmbl.justext.paragraph import Paragraph
-VERSION = "2.0"
ALLOWED_EXCEPTIONS = (ValueError, ConnectionError, ReadTimeout, TimeoutError,
OSError, NewConnectionError, MaxRetryError, SSLCertVerificationError)
@@ -33,7 +32,8 @@ NUM_EXTRACT_CHARS = 155
DEFAULT_ENCODING = 'utf8'
DEFAULT_ENC_ERRORS = 'replace'
MAX_SITE_URLS = 100
-HEADERS = {"User-Agent": f"mwmbl/{VERSION} (https://mwmbl.org)"}
+CRAWLER_VERSION: str = "0.2.0"
+USER_AGENT = f"mwmbl/{CRAWLER_VERSION} (https://mwmbl.org)"
logger = getLogger(__name__)
@@ -45,7 +45,7 @@ def fetch(url):
https://stackoverflow.com/a/22347526
"""
- r = requests.get(url, stream=True, timeout=TIMEOUT_SECONDS, headers=HEADERS)
+ r = requests.get(url, stream=True, timeout=TIMEOUT_SECONDS, headers={"User-Agent": USER_AGENT})
size = 0
start = time.time()