Add data caching to be nicer to the Paper API :D
This commit is contained in:
parent
dcbbdb63f2
commit
d135f31381
@ -15,12 +15,20 @@ def failCheck(response):
|
|||||||
print("Status Code is: "+str(response.status_code))
|
print("Status Code is: "+str(response.status_code))
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise error
|
raise error
|
||||||
|
# Data Caching
|
||||||
|
dataCache = {}
|
||||||
|
def cacheData(function_name, cached_data):
|
||||||
|
print("Caching data!")
|
||||||
|
dataCache[function_name] = cached_data
|
||||||
# This function returns the versions from a project from the Paper API.
|
# This function returns the versions from a project from the Paper API.
|
||||||
def getVersions(project):
|
def getVersions(project):
|
||||||
print("Calling getVersions()...")
|
print("Calling getVersions()...")
|
||||||
|
if "getVersions" in dataCache:
|
||||||
|
return dataCache["getVersions"]
|
||||||
response = requests.get(base_api_url+"/projects/"+project, timeout=timeoutTime)
|
response = requests.get(base_api_url+"/projects/"+project, timeout=timeoutTime)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
|
cacheData("getVersions", api_response['versions'])
|
||||||
return api_response['versions']
|
return api_response['versions']
|
||||||
|
|
||||||
def getLatest(project):
|
def getLatest(project):
|
||||||
@ -30,18 +38,24 @@ def getLatest(project):
|
|||||||
|
|
||||||
def getBuildNumber(project, version):
|
def getBuildNumber(project, version):
|
||||||
print("Calling getBuildNumber()...")
|
print("Calling getBuildNumber()...")
|
||||||
|
if "getBuildNumber" in dataCache:
|
||||||
|
return dataCache["getBuildNumber"]
|
||||||
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version, timeout=timeoutTime)
|
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version, timeout=timeoutTime)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
|
cacheData("getBuildNumber", api_response['builds'])
|
||||||
return api_response['builds']
|
return api_response['builds']
|
||||||
|
|
||||||
def getBuildInfo(project, version):
|
def getBuildInfo(project, version):
|
||||||
print("Calling getBuildInfo()...")
|
print("Calling getBuildInfo()...")
|
||||||
|
if "getBuildInfo" in dataCache:
|
||||||
|
return dataCache["getBuildInfo"]
|
||||||
buildID1 = getBuildNumber(project, version)
|
buildID1 = getBuildNumber(project, version)
|
||||||
buildID = str(buildID1[-1])
|
buildID = str(buildID1[-1])
|
||||||
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID, timeout=timeoutTime)
|
response = requests.get(base_api_url+"/projects/"+project+"/versions/"+version+"/builds/"+buildID, timeout=timeoutTime)
|
||||||
failCheck(response)
|
failCheck(response)
|
||||||
api_response = response.json()
|
api_response = response.json()
|
||||||
|
cacheData("getBuildInfo", api_response)
|
||||||
return api_response
|
return api_response
|
||||||
|
|
||||||
def getJarInfo(project, version):
|
def getJarInfo(project, version):
|
||||||
|
Loading…
Reference in New Issue
Block a user