From 5f9ebe5ef63cc80273de6981d112254a0e05e939 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Thu, 19 Sep 2024 19:03:21 +0200 Subject: Parse entries when collecting The piece of logic that parses the name of the watch_later entry and makes sure that no redirect entries are processed can easily be moved into the entries() generator. This way we don't even generate items that we end up skipping anyway. --- later | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/later b/later index da7d791..0ba6498 100755 --- a/later +++ b/later @@ -43,7 +43,18 @@ def entries(): for entry in sorted(entries, key=get_mtime): if entry.is_file(): mtime = dt.fromtimestamp(get_mtime(entry)) - yield entry.path, entry.name, mtime + + with open(entry.path, "r") as handle: + first = handle.readline().rstrip() + + name = entry.name + if first.startswith("# "): + name = first.strip("# ") + + if name == "redirect entry": + continue + + yield entry.path, name, mtime parser = argparse.ArgumentParser( @@ -78,17 +89,7 @@ except json.decoder.JSONDecodeError: except Exception as err: sys.exit(f"later: {err}") -for path, basename, mtime in entries(): - with open(path, "r") as handle: - first = handle.readline().rstrip() - - name = basename - if first.startswith("# "): - name = first.strip("# ") - - if name == "redirect entry": - continue - +for path, name, mtime in entries(): if args.update_titles and name not in title_map: if re.fullmatch(r"https?://.*", name): try: -- cgit v1.2.3-2-gb3c3