diff --git a/ynr/apps/people/management/commands/reformat_person_indentifiers.py b/ynr/apps/people/management/commands/reformat_person_indentifiers.py index ea33cdb75..3b6f10a90 100644 --- a/ynr/apps/people/management/commands/reformat_person_indentifiers.py +++ b/ynr/apps/people/management/commands/reformat_person_indentifiers.py @@ -1,5 +1,3 @@ -from urllib.parse import urlparse - from django.core.management import call_command from django.core.management.base import BaseCommand from people.models import Person @@ -8,33 +6,33 @@ class Command(BaseCommand): def handle(self, *args, **options): """ - Iterate over all PersonIdentifier objects and reformat the LinkedIn urls as needed. + Iterate over all PersonIdentifier objects and reformat values as needed. """ people = Person.objects.all() for person in people: person_identifiers = person.get_all_identifiers - linkedin_person_identifiers = [ + person_identifiers = [ identifier for identifier in person_identifiers - if identifier.value_type == "linkedin_url" + if identifier.value_type == "instagram_url" ] - # if the parsed_url netloc is uk.linkedin.com, - # then this is a redirect and we need to reformat it to www.linkedin.com - for identifier in linkedin_person_identifiers: - parsed_url = urlparse(identifier.value) - if parsed_url.netloc == "uk.linkedin.com": - # remove the uk. from the netloc - identifier.value = identifier.value.replace("uk.", "www.") - identifier.save() - self.stdout.write( - f"Reformatted LinkedIn URL for {person.name} to {identifier.value}" - ) - else: - self.stdout.write( - f"LinkedIn URL for {person.name} is already in the correct format." - ) - pass + for identifier in person_identifiers: + if identifier.value.startswith("http"): + self.stdout.write( + f"URL for {person.name} is already in the correct format." + ) + pass + else: + if identifier.value.startswith("@"): + username = identifier.value[1:] + identifier.value = ( + f"https://www.instagram.com/{username}" + ) + identifier.save() + self.stdout.write( + f"Reformatted URL for {person.name} to {identifier.value}" + ) call_command("identify_inactive_person_links")