add download game
This commit is contained in:
36
SatiAPI.py
36
SatiAPI.py
@@ -9,6 +9,8 @@ import logging
|
||||
import json
|
||||
import yaml
|
||||
from os.path import exists
|
||||
from os import makedirs
|
||||
|
||||
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
@@ -16,7 +18,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
class SatiAPI:
|
||||
"""A API wrapper for Satisfactory dedicated server"""
|
||||
__AUTHOR__ = 'anima'
|
||||
__VERSION__ = '0.15.0'
|
||||
__VERSION__ = '0.16.1'
|
||||
|
||||
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
|
||||
@@ -188,7 +190,11 @@ class SatiAPI:
|
||||
|
||||
response = requests.post(f'https://{self.host}:{self.port}/api/v1', headers=headers, json=payload, verify=False)
|
||||
if response.status_code == 200:
|
||||
json_response = json.loads(response.text)
|
||||
if response.headers['Content-Type'] == 'application/json':
|
||||
json_response = json.loads(response.text)
|
||||
else:
|
||||
return response.content
|
||||
|
||||
if 'data' in json_response:
|
||||
return json_response
|
||||
else:
|
||||
@@ -455,6 +461,27 @@ class SatiAPI:
|
||||
|
||||
return self.__query('SaveGame', data, True)
|
||||
|
||||
def download_game(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)
|
||||
:type savename: string
|
||||
:param savepath: path to save the savefile
|
||||
:type savepath: sting
|
||||
:return: true if save successfull downloaded
|
||||
:rtype: bool
|
||||
"""
|
||||
if savename is None:
|
||||
pass
|
||||
|
||||
data = dict()
|
||||
data['SaveName'] = savename
|
||||
response = self.__query('DownloadSaveGame', data, True)
|
||||
if not exists(savepath):
|
||||
makedirs(savepath)
|
||||
with open(f'{savepath}/{savename}.sav', 'wb') as f:
|
||||
f.write(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.
|
||||
|
||||
@@ -473,7 +500,6 @@ class SatiAPI:
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_server_options(self) -> dict:
|
||||
"""Retrieves currently applied server options and server options that are still pending application (because of needing session or server restart) Does not require input parameters.
|
||||
|
||||
@@ -499,7 +525,6 @@ class SatiAPI:
|
||||
#ApplyServerOptions
|
||||
#ApplyAdvancedGameSettings
|
||||
|
||||
#DownloadSaveGame
|
||||
#UploadSaveGame
|
||||
|
||||
#DeleteSaveFile
|
||||
@@ -513,4 +538,5 @@ if __name__ == "__main__":
|
||||
print()
|
||||
print(sati.get_sessions())
|
||||
print()
|
||||
print(sati.load_game('MyWorld_APISave'))
|
||||
print(sati.download_game('MyWorld_APISave'))
|
||||
|
||||
Reference in New Issue
Block a user