Last active
November 30, 2018 14:54
-
-
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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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