]> git.scottworley.com Git - paperdoorknob/blobdiff - fetch.py
Progress indicator
[paperdoorknob] / fetch.py
index b99938c055fe8a2fc31f951404ed497849e5dcff..e998394445196fcf677766a78cd3805d6b241bd1 100644 (file)
--- a/fetch.py
+++ b/fetch.py
@@ -13,6 +13,12 @@ from typing import IO, Iterator
 import requests
 import requests_cache
 
 import requests
 import requests_cache
 
+from version import paperdoorknob_version
+
+
+_headers = {'User-Agent': f'paperdoorknob/{paperdoorknob_version} ' +
+            '(https://git.scottworley.com/paperdoorknob/)'}
+
 
 class Fetcher(ABC):
     @abstractmethod
 
 class Fetcher(ABC):
     @abstractmethod
@@ -27,7 +33,7 @@ class _SessionFetcher(Fetcher):
         self._timeout = timeout
 
     def fetch(self, url: str) -> bytes:
         self._timeout = timeout
 
     def fetch(self, url: str) -> bytes:
-        with self._session.get(url, timeout=self._timeout) as r:
+        with self._session.get(url, timeout=self._timeout, headers=_headers) as r:
             r.raise_for_status()
             return r.content
 
             r.raise_for_status()
             return r.content
 
@@ -44,7 +50,7 @@ class _CachingFetcher(Fetcher):
         self._cache_hit_count = 0
 
     def fetch(self, url: str) -> bytes:
         self._cache_hit_count = 0
 
     def fetch(self, url: str) -> bytes:
-        with self._session.get(url, timeout=self._timeout) as r:
+        with self._session.get(url, timeout=self._timeout, headers=_headers) as r:
             r.raise_for_status()
             self._request_count += 1
             self._cache_hit_count += int(r.from_cache)
             r.raise_for_status()
             self._request_count += 1
             self._cache_hit_count += int(r.from_cache)