ExternalService.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:kudubot 作者: namboy94 项目源码 文件源码
def store_message_in_file(self, message: Message) -> Tuple[str, str]:
        """
        Stores a message in a json file.
        The filename of the file will be the current time.
        Also generates a response file location in which the executable may
        write a response into

        :param message: The message to save
        :return: The location of the stored message json file,
                 the location of the response file
        """

        json_data = message.to_dict()

        while True:  # Make sure that file does not exist
            message_file = os.path.join(self.message_dir, str(time.time()))
            if not os.path.isfile(message_file):
                with open(message_file + ".json", 'w') as json_file:
                    json.dump(json_data, json_file)
                return message_file + ".json", message_file + "-response.json"

    # noinspection PyMethodMayBeStatic
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号