From 5d95fed964b050714de52f049a8172122f1e5641 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Tue, 17 Mar 2020 13:26:32 +0100 Subject: Include only 10 (by default) most recent files in the feed. --- gemfeed.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gemfeed.py b/gemfeed.py index f0e9aa9..dcdd7a8 100644 --- a/gemfeed.py +++ b/gemfeed.py @@ -21,14 +21,16 @@ def get_feed_title(): return extract_first_heading(filename, default) return default -def find_files(): +def find_files(n=10): files = [] for extension in ("gmi", "gem", "gemini"): files.extend(glob.glob("*.{}".format(extension))) index = "index.{}".format(extension) if index in files: files.remove(index) - return [f for f in files if is_world_readable(f)] + files = [f for f in files if is_world_readable(f)] + files.sort(key=os.path.getctime, reverse=True) + return files[0:n] def extract_first_heading(filename, default=""): with open(filename) as fp: @@ -71,6 +73,8 @@ def main(): required=True, help='base URL for feed and entries') parser.add_argument('-e', '--email', dest='email', type=str, help="feed author's email address") + parser.add_argument('-n', dest='n', type=int, default=10, + 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('-s', '--subtitle', dest='subtitle', type=str, @@ -104,7 +108,7 @@ def main(): feed.link(href=urljoin(args.base_url, args.output), rel='self') # Add one entry per .gmi file - files = find_files() + files = find_files(args.n) latest_update = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc) for filename in files: entry = feed.add_entry() -- cgit v1.2.3-54-g00ecf