From 818cdaaa9bd3a15a738ee5e645f3239564fd9b48 Mon Sep 17 00:00:00 2001 From: pictuga Date: Mon, 27 Apr 2020 18:00:14 +0200 Subject: [PATCH] Make it possible to call sub-libs in non interactive mode Run `python -m morss.feeds http://lemonde.fr` and so on --- morss/crawler.py | 5 ++++- morss/feeds.py | 4 ++++ morss/readabilite.py | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/morss/crawler.py b/morss/crawler.py index cb081b1..1fbe98a 100644 --- a/morss/crawler.py +++ b/morss/crawler.py @@ -576,4 +576,7 @@ class MySQLCacheHandler(BaseCache): if __name__ == '__main__': - data = get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it') + data, con, contenttype, encoding = adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it') + + if not sys.flags.interactive: + print(data.decode(encoding)) diff --git a/morss/feeds.py b/morss/feeds.py index 6ec72d5..7d4129b 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -761,3 +761,7 @@ if __name__ == '__main__': data, con, contenttype, encoding = crawler.adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://www.nytimes.com/', follow='rss') feed = parse(data, url=con.geturl(), mimetype=contenttype, encoding=encoding) + + if not sys.flags.interactive: + for item in feed.items: + print(item.title, item.link) diff --git a/morss/readabilite.py b/morss/readabilite.py index 9c15c1a..41a6991 100644 --- a/morss/readabilite.py +++ b/morss/readabilite.py @@ -350,3 +350,6 @@ if __name__ == '__main__': data, con, contenttype, encoding = crawler.adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it') article = get_article(data, url=con.geturl(), encoding=encoding) + + if not sys.flags.interactive: + print(article.decode(encoding))