Update document export helper script
This commit is contained in:
parent
93bb7f4473
commit
848f2a36a0
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue