Last active
April 11, 2020 10:43
-
-
Save toastedcornflakes/c15cc90c00967d045d0714bcb4948fa0 to your computer and use it in GitHub Desktop.
A python script to download the latest Paper MC build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import pickle | |
import sys | |
import urllib.request | |
from shutil import move | |
import requests | |
""" | |
A python script to download the latest Paper MC build if it hasn't | |
been downloaded yet. | |
You'll need requests installed: | |
pip install requests | |
""" | |
VERSION = '1.15.2' | |
remote_build = int(requests.get(f"https://papermc.io/api/v1/paper/{VERSION}/latest").json()["build"]) | |
try: | |
with open('latest', 'rb') as latest: | |
old_latest = pickle.load(latest) | |
except (FileNotFoundError, EOFError): | |
old_latest = 0 | |
if old_latest >= remote_build: | |
print(f"Already up-to-date, build #{remote_build}") | |
sys.exit(0) | |
try: | |
move('server.jar', 'server_old.jar') | |
except FileNotFoundError: | |
pass | |
download_url = f"https://papermc.io/api/v1/paper/{VERSION}/{remote_build}/download/" | |
print(f"Downloading {download_url}...") | |
r = requests.get(download_url) | |
with open('server.jar', 'wb+') as outfile: | |
outfile.write(r.content) | |
with open('latest', 'wb+') as latest: | |
pickle.dump(remote_build, latest) | |
print(f"Updated to build #{remote_build}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment