From f663618a9a95f29eed3c3f26e1852b216f16d8ba Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Tue, 14 Dec 2021 20:02:16 -0600 Subject: [PATCH] First working commit! --- .gitignore | 1 + mcUp.py | 18 +++++++++++- parsers/__pycache__/paperMC.cpython-310.pyc | Bin 1207 -> 2291 bytes parsers/paperMC.py | 31 ++++++++++++++++---- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d392f0e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.jar diff --git a/mcUp.py b/mcUp.py index ae9d2c0..ad7a376 100755 --- a/mcUp.py +++ b/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)) diff --git a/parsers/__pycache__/paperMC.cpython-310.pyc b/parsers/__pycache__/paperMC.cpython-310.pyc index 8b975d746f67b1935ef211b57c2121ec28952c4a..e1981eeb602d2fadedcd695c1159636491ef4ecf 100644 GIT binary patch literal 2291 zcmZ`)%aYqf6jk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OS_I*5Z&J{aKcBvrV$g>Olg?&g!n*&sG05wk+Z zp+a>OM`9FvcfY&y=!dvne`fZvKW^ajQ6vMZ|0XpI6sn`9cvfghK(a%IqF51zL1Jof n_|-V)(~KHrlY8COLfIfX@!Y&`D<;btv?+LS_MHE1iN!3F5D`EprEuHl?-B03z^h~OtH|li!!)Y z7e0gf0D=pjz&CK+2he+C6*KTn$UQkX=Z-2*IlogZ<{7Th>dVogHT378KV0eCu**V! z_$K#vu%?*=4FQupU@61D2-pCCY2FqZeowU}tsCA0RNLB4q3sOt4(U?3cOO`fr(8NU zhR$x3J;DMsvsbu}TP4g5@dXRzybD2k^7SB55ca50rywI>+79Gns^*qC9GXkRucb9-&C^2_-~mndg7F zV>eZy$|Qlpto=kXX?#qxN%m3q{5V!MEGN{ZKAss)jn2Z7%4f@7Yu&Uo%_+SK2qgG7 bB{MH$?yaA9WcMuI08}LP?A@yiw_tq(W07a1 diff --git a/parsers/paperMC.py b/parsers/paperMC.py index 1a6d241..1cd57d3 100644 --- a/parsers/paperMC.py +++ b/parsers/paperMC.py @@ -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