diff options
author | Ngô Ngọc Đức Huy <huyngo@disroot.org> | 2023-09-02 10:01:52 +0700 |
---|---|---|
committer | Ngô Ngọc Đức Huy <huyngo@disroot.org> | 2023-09-02 10:01:52 +0700 |
commit | 35e9f6324dba0757e7c967fab6d000e44b4d5074 (patch) | |
tree | 6750e147708092e0397ee2f581f2c9ccd1c00455 /fead.patch | |
parent | 46b1e6c785c9e15e721faa54d6e979c5c226c1a3 (diff) | |
download | blog-35e9f6324dba0757e7c967fab6d000e44b4d5074.tar.gz |
Update theme
Diffstat (limited to 'fead.patch')
-rw-r--r-- | fead.patch | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/fead.patch b/fead.patch new file mode 100644 index 0000000..0915336 --- /dev/null +++ b/fead.patch @@ -0,0 +1,54 @@ +commit 277deed03833377bae0ae68cf7db3f0d3d578ccd +Author: Ngô Ngọc Đức Huy <huyngo@disroot.org> +Date: 2023-08-30 11:01:00 +0700 + + Add option to skip errors + +diff --git a/src/fead.py b/src/fead.py +index 370b623..0b35119 100755 +--- a/src/fead.py ++++ b/src/fead.py +@@ -185,11 +185,23 @@ async def fetch(raw_url): + response.getheaders(), response) + + +-async def fetch_all(urls): ++async def fetch_skip_error(url): ++ try: ++ return await fetch(url) ++ except Exception as e: ++ warn(f'fail to fetch {url}: {e}', ++ type('FailureWarning', (Warning,), {})) ++ return None ++ ++ ++async def fetch_all(urls, skip_error): + """Fetch all given URLs asynchronously and return them parsed.""" +- tasks = gather(*map(fetch, urls)) ++ if skip_error: ++ tasks = gather(*map(fetch_skip_error, urls)) ++ else: ++ tasks = gather(*map(fetch, urls)) + try: +- return await tasks ++ return filter(lambda t: t is not None, await tasks) + except: + tasks.cancel() # structured concurrency + raise +@@ -234,11 +246,15 @@ def main(): + parser.add_argument('-o', '--output', metavar='PATH', + type=FileType('w'), default=stdout, + help='output file (default to stdout)') ++ parser.add_argument('-s', '--skip-error', action='store_true', ++ default=False, ++ help="errors not causing failure but logged") + args = parser.parse_args() + + template = args.template.read() + args.template.close() +- for ad in select(args.count, (ad for feed in run(fetch_all(args.feeds)) ++ for ad in select(args.count, (ad for feed in run(fetch_all(args.feeds, ++ args.skip_error)) + for ad in select(args.per_feed, feed))): + args.output.write(template.format(**truncate(ad, args.len)._asdict())) + args.output.close() |