From ff234aa9d545aa85966a93dfe889ec2dd937f594 Mon Sep 17 00:00:00 2001 From: anima Date: Sun, 22 Sep 2024 00:48:04 +0200 Subject: [PATCH] add delete save --- .gitignore | 1 + SatiAPI.py | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c6317ae..e468142 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.conf *.ymal *.yml +saves/ # ---> Python # Byte-compiled / optimized / DLL files diff --git a/SatiAPI.py b/SatiAPI.py index 247f963..17e0c15 100644 --- a/SatiAPI.py +++ b/SatiAPI.py @@ -18,7 +18,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) class SatiAPI: """A API wrapper for Satisfactory dedicated server""" __AUTHOR__ = 'anima' - __VERSION__ = '0.16.1' + __VERSION__ = '0.17.2' def __init__(self, host: str = None, port: int = 7777, token: str = None, conffile: str = 'conf.yml', logfile: str = 'SatiAPI.log', loglevel: int = 20) -> None: """create a wrapper for satisfactory dedicated server @@ -461,7 +461,7 @@ class SatiAPI: return self.__query('SaveGame', data, True) - def download_game(self, savename: str = None, savepath: str = 'saves/') -> bool: + def download_save(self, savename: str = None, savepath: str = 'saves/') -> bool: """Downloads save game with the given name from the Dedicated Server. Requires Admin privileges. This function responds with the file attachment containing the save game file on success, and with normal error response in case of error. :param savename: Name of the save game file to download from the Dedicated Server. Default: Sessionname_APISave (will be create before) @@ -481,6 +481,25 @@ class SatiAPI: makedirs(savepath) with open(f'{savepath}/{savename}.sav', 'wb') as f: f.write(response) + if exists(f'{savepath}/{savename}.sav'): + return True + else: + return False + + def delete_save(self, savename: str) -> bool: + """Deletes the existing save game file from the server. Requires Admin privileges. SaveName might be changed to satisfy file system restrictions on file names. Function does not return any data on success. + + :param savename: Name of the save game file to delete. Passed name might be sanitized + :type savename: sting + :return: true if save successfull deleted + :rtype: bool + """ + if isinstance(savename, str): + data = dict() + data['SaveName'] = savename + + response = self.__query('DeleteSaveFile', data, True) + return response def load_game(self, savename: str, enableAdvancedSettings: bool = True) -> bool: """Loads the save game file by name, optionally with Advanced Game Settings enabled. Requires Admin privileges. Dedicated Server HTTPS API will become temporarily unavailable when save game is being loaded. Function does not return any data on succcess. @@ -538,5 +557,5 @@ if __name__ == "__main__": print() print(sati.get_sessions()) print() - print(sati.download_game('MyWorld_APISave')) - \ No newline at end of file + # print(sati.download_save('MyWorld_APISave')) + print(sati.delete_save('MyWorld_APISave'))