From ff18a8d9c80c625a0431c1159de2fb84d78f65bb Mon Sep 17 00:00:00 2001 From: rilez366 Date: Tue, 27 May 2025 16:24:51 +0100 Subject: [PATCH 1/2] made changes to script and python syntax --- aws/authentication/generate_aws_resource.py | 5 +- .../scripts/person_table/last_person_ref.log | 2 +- .../person_table/set_personref_field.py | 50 ++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/aws/authentication/generate_aws_resource.py b/aws/authentication/generate_aws_resource.py index df8b091..2eb21e8 100755 --- a/aws/authentication/generate_aws_resource.py +++ b/aws/authentication/generate_aws_resource.py @@ -8,7 +8,10 @@ from enums.enums import Stage -def get_session_for_stage(stage: Stage | str) -> Session: +from typing import Union + +def get_session_for_stage(stage: Union[Stage, str]) -> Session: + if isinstance(stage, Stage): stage_profile = stage.value.lower() else: diff --git a/aws/database/dynamodb/scripts/person_table/last_person_ref.log b/aws/database/dynamodb/scripts/person_table/last_person_ref.log index dc50868..5653fd5 100644 --- a/aws/database/dynamodb/scripts/person_table/last_person_ref.log +++ b/aws/database/dynamodb/scripts/person_table/last_person_ref.log @@ -1 +1 @@ -70121271 \ No newline at end of file +70121276 \ No newline at end of file diff --git a/aws/database/dynamodb/scripts/person_table/set_personref_field.py b/aws/database/dynamodb/scripts/person_table/set_personref_field.py index 1e7c4f8..7002aa7 100644 --- a/aws/database/dynamodb/scripts/person_table/set_personref_field.py +++ b/aws/database/dynamodb/scripts/person_table/set_personref_field.py @@ -1,8 +1,54 @@ +# from aws.database.dynamodb.utils.get_dynamodb_table import get_dynamodb_table +# from enums.enums import Stage + + +# def process_scan(table, scan, next_person_ref): +# for item in scan.get('Items', []): +# table.update_item( +# Key={'id': item['id']}, +# UpdateExpression="SET personRef = :val", +# ExpressionAttributeValues={':val': next_person_ref} +# ) +# print(f"Assigned personRef {next_person_ref} to id {item['id']}") +# next_person_ref += 1 + +# return scan.get('LastEvaluatedKey'), next_person_ref + + +# def main(): +# table = get_dynamodb_table( +# table_name="Persons", +# stage=Stage.HOUSING_PRODUCTION +# ) + +# next_person_ref = 70000000 +# scan = table.scan() + +# while True: +# last_evaluated_key, next_person_ref = process_scan(table, scan, next_person_ref) + +# if last_evaluated_key: +# scan = table.scan(ExclusiveStartKey=last_evaluated_key) +# else: +# break + +# last_assigned_ref = next_person_ref - 1 +# with open('last_person_ref.log', 'w') as f: +# f.write(str(last_assigned_ref)) + +# print(f"Last assigned personRef was: {last_assigned_ref}") +# print("All done!") + + +# if __name__ == "__main__": +# main() + from aws.database.dynamodb.utils.get_dynamodb_table import get_dynamodb_table from enums.enums import Stage +from mypy_boto3_dynamodb.service_resource import Table -def process_scan(table, scan, next_person_ref): +def process_scan(table: Table, scan, next_person_ref: int): for item in scan.get('Items', []): table.update_item( Key={'id': item['id']}, @@ -16,7 +62,7 @@ def process_scan(table, scan, next_person_ref): def main(): - table = get_dynamodb_table( + table: Table = get_dynamodb_table( table_name="Persons", stage=Stage.HOUSING_DEVELOPMENT ) From 1ab97c1fb60967ed60d8e4f01e60d5d6a3e27be0 Mon Sep 17 00:00:00 2001 From: rilez366 Date: Tue, 27 May 2025 16:25:49 +0100 Subject: [PATCH 2/2] removed uncommented script --- .../person_table/set_personref_field.py | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/aws/database/dynamodb/scripts/person_table/set_personref_field.py b/aws/database/dynamodb/scripts/person_table/set_personref_field.py index 7002aa7..3a1175a 100644 --- a/aws/database/dynamodb/scripts/person_table/set_personref_field.py +++ b/aws/database/dynamodb/scripts/person_table/set_personref_field.py @@ -1,48 +1,3 @@ -# from aws.database.dynamodb.utils.get_dynamodb_table import get_dynamodb_table -# from enums.enums import Stage - - -# def process_scan(table, scan, next_person_ref): -# for item in scan.get('Items', []): -# table.update_item( -# Key={'id': item['id']}, -# UpdateExpression="SET personRef = :val", -# ExpressionAttributeValues={':val': next_person_ref} -# ) -# print(f"Assigned personRef {next_person_ref} to id {item['id']}") -# next_person_ref += 1 - -# return scan.get('LastEvaluatedKey'), next_person_ref - - -# def main(): -# table = get_dynamodb_table( -# table_name="Persons", -# stage=Stage.HOUSING_PRODUCTION -# ) - -# next_person_ref = 70000000 -# scan = table.scan() - -# while True: -# last_evaluated_key, next_person_ref = process_scan(table, scan, next_person_ref) - -# if last_evaluated_key: -# scan = table.scan(ExclusiveStartKey=last_evaluated_key) -# else: -# break - -# last_assigned_ref = next_person_ref - 1 -# with open('last_person_ref.log', 'w') as f: -# f.write(str(last_assigned_ref)) - -# print(f"Last assigned personRef was: {last_assigned_ref}") -# print("All done!") - - -# if __name__ == "__main__": -# main() - from aws.database.dynamodb.utils.get_dynamodb_table import get_dynamodb_table from enums.enums import Stage from mypy_boto3_dynamodb.service_resource import Table