diff options
author | Wolfgang Müller | 2024-09-19 19:03:21 +0200 |
---|---|---|
committer | Wolfgang Müller | 2024-09-19 19:03:21 +0200 |
commit | 5f9ebe5ef63cc80273de6981d112254a0e05e939 (patch) | |
tree | 29e12c08ee12ef3ef730362c873891c3f0369fd1 | |
parent | 7e991f08d972505ace6b989bb578d1c4c9ee2ea7 (diff) | |
download | later-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-x | later | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -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: |