import datetime
import jwt

def create_jwt(system_key, device_id, private_key_file, algorithm):
    token = {
        # The time that the token was issued at
        "iat": datetime.datetime.now(tz=datetime.timezone.utc),
        # The time the token expires.
        "exp": datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(minutes=20),
        "sk": system_key,
        "uid": device_id,
        "ut": 3,
    }

    # Read the private key file.
    with open(private_key_file, "r") as f:
        private_key = f.read()

    print(f"Creating JWT using {algorithm} from private key file {private_key_file}\n")

    return jwt.encode(token, private_key, algorithm=algorithm)

systemKey = "mySystemKey"
deviceId = "myDeviceId"
privateKey = "rsa_private.pem"
alg = "RS256"

mqttClientPassword = create_jwt(systemKey, deviceId, privateKey, alg)
print(f"mqttClientPassword: {mqttClientPassword}\n")