From c3e831c9f64538a513e293fd357bada1b267b2b6 Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 23 Nov 2020 14:09:47 +0300 Subject: [PATCH 1/2] Add token_file_path to init args --- pysendpulse/pysendpulse.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pysendpulse/pysendpulse.py b/pysendpulse/pysendpulse.py index 2d38d86..9a29634 100644 --- a/pysendpulse/pysendpulse.py +++ b/pysendpulse/pysendpulse.py @@ -45,7 +45,7 @@ class PySendPulse: MEMCACHED_VALUE_TIMEOUT = 3600 ALLOWED_STORAGE_TYPES = ['FILE', 'MEMCACHED'] - def __init__(self, user_id, secret, storage_type="FILE"): + def __init__(self, user_id, secret, storage_type="FILE", token_file_path=""): """ SendPulse API constructor @param user_id: string REST API ID from SendPulse settings @@ -60,6 +60,7 @@ def __init__(self, user_id, secret, storage_type="FILE"): self.__user_id = user_id self.__secret = secret self.__storage_type = storage_type.upper() + self.__token_file_path = token_file_path m = md5() m.update("{}::{}".format(user_id, secret).encode('utf-8')) self.__token_hash_name = m.hexdigest() From 4962ccfc2db275c89908319799145433eb8c71e2 Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 23 Nov 2020 15:32:10 +0300 Subject: [PATCH 2/2] Auto create token_file_path --- pysendpulse/pysendpulse.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pysendpulse/pysendpulse.py b/pysendpulse/pysendpulse.py index 9a29634..d96422a 100644 --- a/pysendpulse/pysendpulse.py +++ b/pysendpulse/pysendpulse.py @@ -108,6 +108,9 @@ def __get_token(self): else: filepath = "{}{}".format(self.__token_file_path, self.__token_hash_name) try: + if not os.path.isdir(self.__token_file_path): + os.makedirs(self.__token_file_path, exist_ok=True) + with open(filepath, 'w') as f: f.write(self.__token) logger.debug("Set token '{}' into 'FILE' '{}'".format(self.__token, filepath))