aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2024-09-19 19:03:21 +0200
committerWolfgang Müller2024-09-19 19:03:21 +0200
commit5f9ebe5ef63cc80273de6981d112254a0e05e939 (patch)
tree29e12c08ee12ef3ef730362c873891c3f0369fd1
parent7e991f08d972505ace6b989bb578d1c4c9ee2ea7 (diff)
downloadlater-5f9ebe5ef63cc80273de6981d112254a0e05e939.tar.gz
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.
-rwxr-xr-xlater25
1 files 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: