Skip to content

Instantly share code, notes, and snippets.

@toastedcornflakes
Last active April 11, 2020 10:43
Show Gist options
  • Save toastedcornflakes/c15cc90c00967d045d0714bcb4948fa0 to your computer and use it in GitHub Desktop.
Save toastedcornflakes/c15cc90c00967d045d0714bcb4948fa0 to your computer and use it in GitHub Desktop.
A python script to download the latest Paper MC build
#!/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