From acbee0af9e847419eaa9809ec455fb37b455c42a Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Tue, 17 Mar 2020 18:50:21 +0100 Subject: Only write to stdout when asked, to facilitate use in scripts instead of as a command line tool. --- gemfeed.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'gemfeed.py') diff --git a/gemfeed.py b/gemfeed.py index 0f42141..23ca0aa 100644 --- a/gemfeed.py +++ b/gemfeed.py @@ -90,7 +90,8 @@ def populate_entry_from_file(filename, base_url, entry): title = extract_first_heading(filename, filename) entry.title(title) -def build_feed(base_url, output="atom.xml", n=10, title="", subtitle="", author="", email=""): +def build_feed(base_url, output="atom.xml", n=10, title="", subtitle="", + author="", email="", verbose=False): """ Build an Atom feed for all world readable Gemini files in the current directory, and write it to atom.xml. @@ -118,18 +119,21 @@ def build_feed(base_url, output="atom.xml", n=10, title="", subtitle="", author= # Add one entry per .gmi file files = find_files(n) if not files: - print("No world-readable Gemini content found! :(") + if verbose: + print("No world-readable Gemini content found! :(") return for n, filename in enumerate(files): entry = feed.add_entry() populate_entry_from_file(filename, base_url, entry) - print("Adding {} with title '{}'...".format(filename, entry.title())) if n == 0: feed.updated(entry.updated()) + if verbose: + print("Adding {} with title '{}'...".format(filename, entry.title())) # Write file feed.atom_file(output, pretty=True) - print("Wrote Atom feed to {}.".format(output)) + if verbose: + print("Wrote Atom feed to {}.".format(output)) def main(): """ @@ -148,6 +152,8 @@ def main(): help='include N most recently created files in feed (default 10)') parser.add_argument('-o', '--output', dest='output', type=str, default="atom.xml", help='output filename') + parser.add_argument('-q', '--quiet', dest='verbose', action="store_false", + help='Write nothing to stdout under non-error conditions') parser.add_argument('-s', '--subtitle', dest='subtitle', type=str, help='feed subtitle') parser.add_argument('-t', '--title', dest='title', type=str, @@ -164,7 +170,7 @@ def main(): # Build the feed build_feed(args.base_url, args.output, args.n, args.title, args.subtitle, - args.author, args.email) + args.author, args.email, args.verbose) if __name__ == "__main__": main() -- cgit v1.2.3-54-g00ecf