Skip to content

Instantly share code, notes, and snippets.

@redthing1
Last active August 1, 2023 22:15
Show Gist options
  • Save redthing1/6c6c78e6e517d6003dde87b98b5fccae to your computer and use it in GitHub Desktop.
Save redthing1/6c6c78e6e517d6003dde87b98b5fccae to your computer and use it in GitHub Desktop.
Download your time machine data from Solaris

Here's a tool to download Solaris time machine data.

Setup:

pip3 install typer requests

Usage:

python3 timemachine.py -e <email> -p <password> -g <gameid> -o <outputdir>
import typer
import requests
import json
import os
app = typer.Typer(
name="Timemachine",
help="Downloads Solaris time machine data",
add_completion=False,
pretty_exceptions_show_locals=False,
)
@app.command(no_args_is_help=True)
def cli(
game_id: str = typer.Option(..., "-g", help="Game ID"),
save_dir: str = typer.Option(..., "-o", help="Directory to save files to"),
email: str = typer.Option(..., "-e", help="Email address"),
password: str = typer.Option(..., "-p", help="Password"),
api_url: str = typer.Option(
"https://api.solaris.games", help="Server API base URL"
),
):
# login
print(f"Logging in to {api_url} as {email}")
sess = requests.Session()
sess.headers.update({"User-Agent": "Solaris Time Machine Downloader"})
login_res = sess.post(
f"{api_url}/api/auth/login", json={"email": email, "password": password}
)
login_res.raise_for_status()
login_res_data = login_res.json()
print(f" Logged in as {login_res_data['username']}")
print(" Cookies:", sess.cookies.get_dict())
# get game info
print(f"Getting game info for {game_id}")
game_sync_res = sess.get(f"{api_url}/api/game/{game_id}/galaxy")
game_sync_res.raise_for_status()
game_sync_res_data = game_sync_res.json()
game_name = game_sync_res_data["settings"]["general"]["name"]
game_tick = game_sync_res_data["state"]["tick"]
print(f" Game name: {game_name}")
print(f" Tick: {game_tick}")
# get intel
print(f"Getting intel for {game_id}")
game_intel_res = sess.get(f"{api_url}/api/game/{game_id}/intel")
game_intel_res.raise_for_status()
game_intel_res_data = game_intel_res.json()
print(f" Intel: {len(game_intel_res_data)} entries")
with open(os.path.join(save_dir, "intel.json"), "w") as f:
json.dump(game_intel_res_data, f)
# fetch sync data for each tick and save to file
print(f"Downloading time machine data for {game_id}")
os.makedirs(save_dir, exist_ok=True)
for tick in range(0, game_tick + 1):
print(f" Tick {tick}...")
tick_sync_res = sess.get(f"{api_url}/api/game/{game_id}/galaxy/?tick={tick}")
tick_sync_res.raise_for_status()
tick_sync_res_data = tick_sync_res.json()
with open(os.path.join(save_dir, f"tick_{tick:05}.json"), "w") as f:
json.dump(tick_sync_res_data, f)
if __name__ == "__main__":
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment