diff options
author | Ben Sima <ben@bsima.me> | 2025-02-07 13:12:36 -0500 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2025-02-07 13:14:08 -0500 |
commit | ac0a909b1fe95aaaefe029a0ff5b78864f775b42 (patch) | |
tree | f05160f09a85c188b63f23d50669aecc70fb9a2e /textract | |
parent | 15a35828209c08cd263bf1317505ffddfe53a5c5 (diff) |
python fixes
Diffstat (limited to 'textract')
-rwxr-xr-x | textract | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1,20 +1,20 @@ #! /usr/bin/env nix-shell -#! nix-shell -i python -p "python3.withPackages(p: [p.requests p.pyreadability])" +#! nix-shell -i python -p "python3.withPackages(p: [p.pyreadability])" import argparse -from readability import Document -import requests +import readability import sys -cli = argparse.ArgumentParser('read a url') -cli.add_argument('url', type=str) +cli = argparse.ArgumentParser('read a file') +cli.add_argument('file', type=str) args = cli.parse_args() try: - resp = requests.get(args.url) - doc = Document(resp.text) + with open(args.file, 'r') as f: + content = f.read() + doc = readability.Document(content) sys.stdout.write(doc.summary()) -except: - print("textract: Could not fetch document.") +except Exception as e: + print(f"textract: Could not process document. Error: {e}") sys.exit(1) |