Skip to content

Commit

Permalink
Default MC version now latest stable release
Browse files Browse the repository at this point in the history
  • Loading branch information
tjkessler committed Dec 3, 2023
1 parent d4e7e6b commit 00c84e6
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions papermc_updater/update_paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import urllib.request
import urllib.error

MC_VERSION = "1.20.2"


def parse_args() -> dict:
""" parse_args: parse command line arguments in form:
Expand All @@ -29,12 +27,30 @@ def parse_args() -> dict:
ap.add_argument(
"--version",
type=str,
default=MC_VERSION,
help=f"MC version (default: {MC_VERSION})"
default=get_latest_mc_version(),
help=f"MC version (default: {get_latest_mc_version()})"
)
return vars(ap.parse_args(argv[1:]))


def get_latest_mc_version() -> str:
""" get_latest_mc_version: obtain the latest MC version (stable)
Args:
None
Returns:
str: latest MC version (e.g., "1.20.2")
"""

response = urllib.request.urlopen(
f"https://api.papermc.io/v2/projects/paper/"
)
content = json.loads(response.read().decode("utf-8"))
latest_version = content["versions"][-1]
return latest_version


def get_latest_paper_build(version: str) -> int:
""" get_latest_paper_build: obtain the latest PaperMC build (integer
number) from api.papermc.io
Expand Down

0 comments on commit 00c84e6

Please sign in to comment.