From 848f2a36a0979c73c690b4c5c5458de3742f2d49 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 6 Dec 2023 09:23:56 +0100 Subject: [PATCH] Update document export helper script --- server/handle_content_block.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/handle_content_block.py b/server/handle_content_block.py index 34996602..41ee9b6d 100644 --- a/server/handle_content_block.py +++ b/server/handle_content_block.py @@ -7,6 +7,9 @@ from books.models.custom_document import CustomDocument # from books.schema.nodes.content import ContentBlockNode from graphql_relay import to_global_id +""" +Script with helpers to make a CSV export of old document links to compare them to new document links +""" columns = [ "content_block_id", @@ -38,6 +41,33 @@ def handle_all_content_blocks(): handle_content_block(content_block=cb, contents=cb.contents, writer=writer) +def handle_even_older_backup(): # helper to get backup from february and may 2023 and compare the old link with the old link from october + output_columns = columns + ["older", "older_s3"] + with open("old-links.csv", mode="r", encoding="utf-8") as file: + with open("even-older-links.csv", mode="w", encoding="utf-8") as destination: + reader = csv.DictReader(file) + writer = csv.DictWriter(destination, fieldnames=output_columns) + writer.writeheader() + + for row in reader: + try: + document_id = row["document_id"] + if document_id == "": + continue + document = CustomDocument.objects.get(id=document_id) + old_s3_url = format_link_s3(document) + old_django_url = format_link_django(document) + + if row["old_s3"] == old_s3_url: + continue + row["older"] = old_django_url + row["older_s3"] = old_s3_url + + writer.writerow(row) + except CustomDocument.DoesNotExist: + continue + + def fill_csv_with_old_data(): with open("source.csv", mode="r", encoding="utf-8") as file: with open("output.csv", mode="w", encoding="utf-8") as destination: