WIP, API isn't fully implemented
This commit is contained in:
parent
17f41f1312
commit
04dd202e11
36
mcUp.py
Executable file
36
mcUp.py
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/python
|
||||
# Setup Parser
|
||||
import parsers.paperMC
|
||||
import argparse
|
||||
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')
|
||||
parser.add_argument('action', metavar='action', help='what action to execute')
|
||||
parser.add_argument('subAction', metavar='subAction', help='what sub action to execute')
|
||||
args = parser.parse_args()
|
||||
print("mcUp.py, written by Caleb Fontenot")
|
||||
|
||||
# PaperMC command functions
|
||||
def paperMC(project, action, subAction):
|
||||
if action == "get":
|
||||
if subAction == "versions":
|
||||
print(parsers.paperMC.getVersions(project))
|
||||
elif subAction == "latest":
|
||||
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":
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#print(type(getVersionVelocity))
|
||||
|
||||
#print("Latest build of velocity is", parsers.paperMC.getLatest#("velocity"))
|
||||
|
||||
# Determine which API to use:
|
||||
if args.api == "paperMC":
|
||||
paperMC(args.project, args.action, args.subAction)
|
||||
else:
|
||||
print("Error: Unknown API: "+args.api)
|
BIN
parsers/__pycache__/paperMC.cpython-310.pyc
Normal file
BIN
parsers/__pycache__/paperMC.cpython-310.pyc
Normal file
Binary file not shown.
38
parsers/paperMC.py
Normal file
38
parsers/paperMC.py
Normal file
@ -0,0 +1,38 @@
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user