Skip to content

Instantly share code, notes, and snippets.

@jobel-code
Last active November 30, 2018 14:54
Show Gist options
  • Save jobel-code/195af845365871a9e6438af15a0900bc to your computer and use it in GitHub Desktop.
Save jobel-code/195af845365871a9e6438af15a0900bc to your computer and use it in GitHub Desktop.
Generates the equivalent of an uuid3 but qualifing only by datetime.utcnow()
from hashlib import md5
from uuid import UUID, uuid4
from datetime import datetime
def version_uuid_by_date()->str:
"""Generates the equivalent of an uuid3 but qualifing only by datetime.utcnow()
example:
'2018-11-15' will return 'f77ef8a9-a377-3083-b131-148cded89c95'
"""
utcnow = datetime.utcnow().strftime('%Y-%m-%d')
hash = md5(bytes(str(utcnow), "utf-8")).digest()
return str(UUID(bytes=hash[:16], version = 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment