summaryrefslogtreecommitdiff
path: root/textract
blob: f80be363c6b8b9b902c405d52c7d3e7ad3b4ae61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /usr/bin/env nix-shell
#! nix-shell -i python -p "python3.withPackages(p: [p.requests p.pyreadability])"

import argparse
from readability import Document
import requests
import sys

cli = argparse.ArgumentParser('read a url')
cli.add_argument('url', type=str)

if __name__ == '__main__':
    args = cli.parse_args()
    try:
        resp = requests.get(args.url)
        doc = Document(resp.text)
        sys.stdout.write(doc.summary())
        sys.exit(0)
    except:
        print("Could not fetch document.")
        sys.exit(1)