in-progress download script:
Code: Select all
import requests
from Utils import is_windows, is_linux
def get_latest_factorio(user: str, password: str, version: str = "latest", build: str = "alpha"):
if is_windows:
distro = "win64-manual"
elif is_linux:
distro = "linux64" # TODO: test
else:
raise NotImplemented(f"No auto downloader implemented for current platform.")
login_url = 'https://factorio.com/login'
with requests.Session() as client:
client.headers.update({'Referer': login_url})
response = client.get(login_url)
html = response.content.decode("utf-8-sig")
tokenstarttext = '<input id="csrf_token" name="csrf_token" type="hidden" value="'
start = html.index(tokenstarttext)
length = html[start:].index('">')
token = html[start + len(tokenstarttext):start + length]
print(token)
login_response = client.post(login_url, data={
"csrf_token": token,
"username_or_email": user,
"password": password
})
if "<h2>Error</h2>" in login_response.text:
start = login_response.text.index("<h2>Error</h2>")
print(login_response.text[start:start+250])
return
response = client.get(f"https://www.factorio.com/get-download/{version}/{build}/{distro}")
return response
response = get_latest_factorio("Test", "Test")