add delete save
This commit is contained in:
27
SatiAPI.py
27
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'))
|
||||
|
||||
# print(sati.download_save('MyWorld_APISave'))
|
||||
print(sati.delete_save('MyWorld_APISave'))
|
||||
|
||||
Reference in New Issue
Block a user