Minecraft-Updater/parsers/paperMC.py

39 lines
1.4 KiB
Python
Raw Normal View History

2021-12-14 18:09:16 -06:00
import requests
debug = False
if debug == True:
import logging
from requests import api
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
timeoutTime = 1
base_api_url = "https://papermc.io/api/v2"
# This function returns the versions from a project from the Paper API.
def getVersions(project):
print("Accessing "+base_api_url+"/projects/"+project+"...")
response = requests.get(base_api_url+"/projects/"+project, timeout=timeoutTime)
print("Status Code is: "+str(response.status_code))
api_response = response.json()
return api_response['versions']
def getLatest(project):
versions = getVersions(project)
return versions[-1]
def getBuildNumber(project, version):
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version, timeout=timeoutTime)
print("Status Code is: "+str(response.status_code))
api_response = response.json()
return api_response['builds']
def getJarName(project, version):
def downloadVersion(project, version):
jarName = getJarName(project, version)
buildID = getBuildNumber(project, version)
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID+"/downloads/"+jarName, timeout=timeoutTime)