Add initial support for Modrinth
This commit is contained in:
parent
d135f31381
commit
0e578fd7d2
13
mcUp.py
13
mcUp.py
@ -1,6 +1,7 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
# Setup Parser
|
# Setup Parser
|
||||||
import parsers.paperMC
|
import parsers.paperMC
|
||||||
|
import parsers.modrinth
|
||||||
import argparse
|
import argparse
|
||||||
import shutil
|
import shutil
|
||||||
import hashlib
|
import hashlib
|
||||||
@ -46,10 +47,20 @@ def paperMC(project, action, subAction):
|
|||||||
print("sha256sum of downloaded file matches the sum that the API gave, jar is safe to use")
|
print("sha256sum of downloaded file matches the sum that the API gave, jar is safe to use")
|
||||||
else:
|
else:
|
||||||
raise error
|
raise error
|
||||||
|
# modrinth command functions
|
||||||
|
def modrinth(project, action, subAction):
|
||||||
|
if action == "list":
|
||||||
|
if subAction == "info":
|
||||||
|
print(parsers.modrinth.modInfo(project))
|
||||||
|
if subAction == "versions":
|
||||||
|
print(parsers.modrinth.getAllModVersionInfo(project))
|
||||||
|
|
||||||
|
|
||||||
# Determine which API to use:
|
|
||||||
|
# Determine which API parser to use:
|
||||||
if args.api == "paperMC":
|
if args.api == "paperMC":
|
||||||
paperMC(args.project, args.action, args.subAction)
|
paperMC(args.project, args.action, args.subAction)
|
||||||
|
elif args.api == "modrinth":
|
||||||
|
modrinth(args.project, args.action, args.subAction)
|
||||||
else:
|
else:
|
||||||
print("Error: Unknown API: "+args.api)
|
print("Error: Unknown API: "+args.api)
|
63
parsers/modrinth.py
Normal file
63
parsers/modrinth.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
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 =
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user