summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2020-03-17 18:50:21 +0100
committerSolderpunk <solderpunk@sdf.org>2020-03-17 18:50:21 +0100
commitacbee0af9e847419eaa9809ec455fb37b455c42a (patch)
tree95dbff2b408505914cdef4ff28f970e821e65cd9
parent333cc83282c8e8e2228c33ee6622f42f91fb6d6f (diff)
Only write to stdout when asked, to facilitate use in scripts instead of as a command line tool.
-rw-r--r--gemfeed.py16
1 files changed, 11 insertions, 5 deletions
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()