Untitled

 avatar
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
def update_bookmark_index(bookmark_record, lines_purged):
    #bookmark_file = "bookmark_log.properties"  # Replace with the actual bookmark file path
    bookmark_record = bookmark_record
    print("Bookmark Record in update_bookmark_index function is : ",bookmark_record)
    logging.info("Bookmark Record in update_bookmark_index function is : %s",bookmark_record)
    # Read the current bookmark index from the bookmark file
    bookmark_index = None
    with open(bookmark_properties_file, "r") as file:
        for line in file:
            if bookmark_record in line:
                bookmark_index = int(line.split("=")[1])
                break

    if bookmark_index is not None:
        # Calculate the updated bookmark index
        updated_index = bookmark_index - lines_purged

        # Update the bookmark file with the new index
        with open(bookmark_properties_file, "w") as file:  ## Changes made here
            file.write(f"{bookmark_record}={updated_index}\n")

        print("Bookmark index updated:", updated_index)
        logging.info("Bookmark index updated: %s ",updated_index)
    else:
        print(f"Failed to update bookmark index for {bookmark_record}. Make sure the record exists in the bookmark file.")
        logging.error("Failed to update bookmark index. Make sure the record exists in the bookmark file. %s ", bookmark_record)


purge_logs()
Editor is loading...