Source code for hastegeo.core.utils.metadata
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import hashlib
import random
import uuid
from datetime import datetime, timezone
[docs]class MetadataUtils:
[docs] @staticmethod
def generate_short_int_id(digits=4):
return str(random.randint(0, 9999)).zfill(digits)
[docs] @staticmethod
def hash_string(string: str):
return hashlib.sha256(string.encode()).hexdigest()
[docs] @staticmethod
def append_status_message(
status_message: str, message: str, timestamp: str = None
):
if status_message is None:
status_message = ""
timestamp = timestamp if timestamp else MetadataUtils.get_timestamp()
return status_message + f"\n{timestamp}: {message}"