summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2020-03-17 13:26:32 +0100
committerSolderpunk <solderpunk@sdf.org>2020-03-17 13:26:32 +0100
commit5d95fed964b050714de52f049a8172122f1e5641 (patch)
tree630ff34bec5ba0ba290ca4c77420a07c29fe1c20
parent63f7622d4c0e6f4a90068009ff4b93412a141901 (diff)
Include only 10 (by default) most recent files in the feed.
-rw-r--r--gemfeed.py10
1 files 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()