64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
from os import error
|
|
import requests
|
|
debug = True
|
|
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://api.modrinth.com/api/v1"
|
|
def failCheck(response):
|
|
print("Status Code is: "+str(response.status_code))
|
|
if response.status_code != 200:
|
|
raise error
|
|
# Data Caching
|
|
dataCache = {}
|
|
def cacheData(function_name, cached_data):
|
|
print("Caching data!")
|
|
dataCache[function_name] = cached_data
|
|
#
|
|
def modInfo(project):
|
|
print("Calling modInfo()...")
|
|
if "modInfo" in dataCache:
|
|
return dataCache["modInfo"]
|
|
response = requests.get(base_api_url+"/mod/"+project)
|
|
failCheck(response)
|
|
api_response = response.json()
|
|
cacheData("modInfo", api_response)
|
|
return api_response
|
|
|
|
def getVersions(project):
|
|
print("Calling getVersions()...")
|
|
if "getVersions" in dataCache:
|
|
return dataCache["getVersions"]
|
|
workingDict = modInfo(project)
|
|
versions = workingDict["versions"]
|
|
print(versions)
|
|
return versions
|
|
|
|
def getAllModVersionInfo(project):
|
|
print("Calling getAllModVersionInfo()...")
|
|
if "getAllModVersionInfo" in dataCache:
|
|
return dataCache["getAllMinecraftVersionInfo"]
|
|
versions = getVersions(project)
|
|
responseList = []
|
|
numberOfVersions = len(versions)
|
|
for item in range(numberOfVersions):
|
|
response = requests.get(base_api_url+"/version/"+versions[item])
|
|
api_response = response.json()
|
|
responseList.append(api_response)
|
|
cacheData("getAllMinecraftVersionInfo", responseList)
|
|
return responseList
|
|
|
|
def determineLatestMinecraftVersion(project):
|
|
modInfo = getAllModVersionInfo(project)
|
|
numberOfVersions = len(modInfo)
|
|
gameVersions = {}
|
|
#for item in range(numberOfVersions):
|
|
#gameVersions =
|
|
|