about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2024-01-10 07:32:50 +0900
committerNguyễn Gia Phong <cnx@loang.net>2024-01-10 07:59:12 +0900
commit2fe8dbaef058254b9ee6f0b9bfcfaf2e943c8df8 (patch)
treef5be53143e5afbc4587f44aeaf18e336728faa82
parent3307272b559048c8393801b792525917ca397071 (diff)
downloadfead-2fe8dbaef058254b9ee6f0b9bfcfaf2e943c8df8.tar.gz
Clarify errors and warnings
-rwxr-xr-xsrc/fead.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/fead.py b/src/fead.py
index dd47266..a01616b 100755
--- a/src/fead.py
+++ b/src/fead.py
@@ -24,6 +24,7 @@ from collections import namedtuple
 from datetime import datetime
 from email.utils import parsedate_to_datetime
 from http.client import HTTPResponse
+from importlib import import_module
 from io import BytesIO
 from operator import attrgetter
 from pathlib import Path
@@ -43,6 +44,9 @@ HTML_TAG = regex('<.+?>')
 Advert = namedtuple('Advert', ('source_title', 'source_link',
                                'title', 'link', 'time', 'summary'))
 
+# Show only message in warnings.
+import_module('warnings').formatwarning = 'Warning: {}\n'.format
+
 
 class GNUHelpFormatter(HelpFormatter):
     """Help formatter for ArgumentParser following GNU Coding Standards."""
@@ -151,7 +155,7 @@ async def fetch(raw_url):
     elif url.scheme == 'http':
         reader, writer = await open_connection(url.hostname, 80)
     else:
-        raise ValueError(f'unsupported URL scheme: {url.scheme}')
+        raise ValueError(f'unsupported URL scheme: {raw_url}')
     try:
         writer.write(REQUEST.format(f"{url.path or '/'}?{url.query}",
                                     url.hostname).encode())
@@ -169,8 +173,7 @@ async def fetch(raw_url):
                             response.getheaders(), response)
         if response.status >= 300:
             location = urljoin(raw_url, response.getheader('Location'))
-            warn(f'{raw_url} -> {location}',
-                 type('RedirectWarning', (Warning,), {}))
+            warn(f'{raw_url} redirected to {location}')
             return await fetch(location)
         if response.status >= 200:
             try: