diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/fead.py | 9 |
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: |