First working commit!
This commit is contained in:
parent
04dd202e11
commit
f663618a9a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.jar
|
18
mcUp.py
18
mcUp.py
@ -2,6 +2,7 @@
|
||||
# Setup Parser
|
||||
import parsers.paperMC
|
||||
import argparse
|
||||
import shutil
|
||||
parser = argparse.ArgumentParser(description='A command-line tool to update a Minecraft Server.')
|
||||
parser.add_argument('api', metavar='api', help='which API to use')
|
||||
parser.add_argument('project', metavar='project', help='which project to query for')
|
||||
@ -19,7 +20,22 @@ def paperMC(project, action, subAction):
|
||||
latestVersion = parsers.paperMC.getLatest(project)
|
||||
buildNumber = parsers.paperMC.getBuildNumber(project, latestVersion)
|
||||
print("Latest version of "+project+" is "+latestVersion+" build #"+str(buildNumber[-1]))
|
||||
elif action == "download":
|
||||
if action == "download":
|
||||
if subAction == "latest":
|
||||
latestVersion = parsers.paperMC.getLatest(project)
|
||||
output = parsers.paperMC.getJarInfo(project, latestVersion)
|
||||
print(output["name"])
|
||||
with parsers.paperMC.downloadVersion(project, latestVersion) as raw:
|
||||
with open(output["name"], 'wb') as file_object:
|
||||
shutil.copyfileobj(raw.raw, file_object)
|
||||
print("Downloaded "+latestVersion+" to "+output["name"])
|
||||
|
||||
|
||||
#latestVersion = parsers.paperMC.getLatest(project)
|
||||
#jarInfo = parsers.paperMC.getJarInfo(project, latestVersion)
|
||||
#print(jarInfo)
|
||||
#print(jarInfo[0])
|
||||
#print(type(jarInfo))
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -12,6 +12,7 @@ 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))
|
||||
@ -19,20 +20,38 @@ def getVersions(project):
|
||||
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 getJarName(project, version):
|
||||
|
||||
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):
|
||||
jarName = getJarName(project, version)
|
||||
buildID = getBuildNumber(project, version)
|
||||
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID+"/downloads/"+jarName, timeout=timeoutTime)
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user