From ac0a909b1fe95aaaefe029a0ff5b78864f775b42 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 7 Feb 2025 13:12:36 -0500 Subject: python fixes --- textract | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'textract') diff --git a/textract b/textract index 707cd27..4a29f55 100755 --- a/textract +++ b/textract @@ -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) -- cgit v1.2.3