From ac0a909b1fe95aaaefe029a0ff5b78864f775b42 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 7 Feb 2025 13:12:36 -0500 Subject: python fixes --- replace | 2 +- textract | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/replace b/replace index e8aa599..5af14b2 100755 --- a/replace +++ b/replace @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.8 +#!/usr/bin/env python """ replace stuff in a file or files """ 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