Преглед изворни кода

Working version. Using latest of everything.

Sacha Ligthert пре 1 година
родитељ
комит
44f2ae9e62
2 измењених фајлова са 29 додато и 1 уклоњено
  1. 3 1
      README.md
  2. 26 0
      fetcher.py

+ 3 - 1
README.md

@@ -1,3 +1,5 @@
 # minecraft_server_downloader
 
-Grab the latest minecraft server.jar binary (to hand off to other tools)
+Grab the latest minecraft server.jar binary.
+
+Uses Python3 and the Requests library.

+ 26 - 0
fetcher.py

@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+import requests
+
+# Fetch some manifests
+url="https://launchermeta.mojang.com/mc/game/version_manifest.json"
+stage1 = requests.get(url)
+latest = stage1.json()["latest"]["release"]
+
+print("Latest version of Minecraft (Release):",latest)
+
+# Iterate through the json, grab the manifest of the newest version
+for version in stage1.json()["versions"]:
+    if latest == version["id"]:
+        # print(version)
+        url = version["url"]
+
+# Grab it. Print.
+stage2 = requests.get(url)
+print("Downloading:",stage2.json()["downloads"]["server"]["url"])
+
+print("Grabbing server.jar")
+jarfile = requests.get(stage2.json()["downloads"]["server"]["url"])
+open("server.jar", "wb").write(jarfile.content)
+
+print("Done!")