Skip to content

Instantly share code, notes, and snippets.

@dawidgora
Last active September 13, 2024 20:25
Show Gist options
  • Save dawidgora/464e065d79d2791fddf61d7b0367c7ef to your computer and use it in GitHub Desktop.
Save dawidgora/464e065d79d2791fddf61d7b0367c7ef to your computer and use it in GitHub Desktop.
Simple bulk uuid v4 validator generated by GPT-4o
import uuid
def is_valid_uuid4(u):
try:
val = uuid.UUID(u, version=4)
# Check if it is truly a UUID4 (random) and not any other UUID type.
return str(val) == u and val.version == 4
except ValueError:
return False
def main():
print("Please paste a list of UUIDs (one per line). Press Enter on an empty line to finish:")
# Capture multiple lines of input from the user
uuid_list = []
while True:
user_input = input().strip()
if not user_input:
break
uuid_list.append(user_input)
invalid_uuids = []
valid_uuid4_count = 0
# Check each UUID in the list
for u in uuid_list:
if is_valid_uuid4(u):
valid_uuid4_count += 1
else:
invalid_uuids.append(u)
# Print results
if invalid_uuids:
print("\nInvalid UUIDs:")
for invalid_uuid in invalid_uuids:
print(invalid_uuid)
else:
print("\nNo invalid UUIDs found.")
print(f"\nNumber of valid UUIDv4: {valid_uuid4_count}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment