From 94f9daeec483e3e6e8e2190a0acbef177885164b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 24 Apr 2022 17:56:52 +0100 Subject: [PATCH] Write hashtag index in one go --- inbox.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/inbox.py b/inbox.py index 21025d673..908d4298c 100644 --- a/inbox.py +++ b/inbox.py @@ -256,13 +256,17 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str, except OSError: print('EX: unable to write ' + tags_filename) else: - if post_url not in open(tags_filename).read(): + content = '' + try: + with open(tags_filename, 'r') as tags_file: + content = tags_file.read() + except OSError: + pass + if post_url not in content: + content = tag_line + content try: - with open(tags_filename, 'r+') as tags_file: - content = tags_file.read() - if tag_line not in content: - tags_file.seek(0, 0) - tags_file.write(tag_line + content) + with open(tags_filename, 'w+') as tags_file: + tags_file.write(content) except OSError as ex: print('EX: Failed to write entry to tags file ' + tags_filename + ' ' + str(ex))