From ae449a426f047c3574749b6ae1f5d2f5c28ad640 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Thu, 19 Sep 2024 19:07:44 +0200 Subject: Have entries() continue early if an entry is not a file This makes this already quite deeply nested function a bit easier to read. --- later | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/later b/later index 0ba6498..70e45e9 100755 --- a/later +++ b/later @@ -41,20 +41,22 @@ def entries(): with os.scandir(watch_later_dir) as entries: for entry in sorted(entries, key=get_mtime): - if entry.is_file(): - mtime = dt.fromtimestamp(get_mtime(entry)) + if not entry.is_file(): + continue - with open(entry.path, "r") as handle: - first = handle.readline().rstrip() + mtime = dt.fromtimestamp(get_mtime(entry)) - name = entry.name - if first.startswith("# "): - name = first.strip("# ") + with open(entry.path, "r") as handle: + first = handle.readline().rstrip() - if name == "redirect entry": - continue + name = entry.name + if first.startswith("# "): + name = first.strip("# ") - yield entry.path, name, mtime + if name == "redirect entry": + continue + + yield entry.path, name, mtime parser = argparse.ArgumentParser( -- cgit v1.2.3-2-gb3c3