58 lines
2.2 KiB
Python

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("Calling getVersions()...")
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):
print("Calling getLatest()...")
versions = getVersions(project)
return versions[-1]
def getBuildNumber(project, version):
print("Calling getBuildNumber()...")
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 getBuildInfo(project, version):
print("Calling getBuildInfo()...")
buildID1 = getBuildNumber(project, version)
buildID = str(buildID1[-1])
print(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID)
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID, timeout=timeoutTime)
api_response = response.json()
return api_response
def getJarInfo(project, version):
print("Calling getJarInfo()...")
buildInfo = getBuildInfo(project, version)
workingDict = buildInfo["downloads"]
workingDict2 = workingDict["application"]
print(workingDict2)
return workingDict2
def downloadVersion(project, version):
print("Calling downloadVersion()...")
jarName = getJarInfo(project, version)
buildID1 = getBuildNumber(project, version)
buildID = str(buildID1[-1])
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID+"/downloads/"+jarName["name"], stream=True, timeout=timeoutTime)
return response