Add version searching!

This commit is contained in:
2022-02-27 20:20:41 -06:00
parent aaa72fd6e6
commit 702690aada
2 changed files with 84 additions and 37 deletions

View File

@@ -9,6 +9,7 @@ import datetime
import iso8601
import pytz
from urllib.parse import unquote
import re
debug = True
if debug == True:
import logging
@@ -19,6 +20,8 @@ if debug == True:
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
timeoutTime = 1
#Setup re
#regex = re.compile(r'*')
# Setup session, this lets the parser re-use the connection instead of establishing a new connection for EACH request, not only does this cause a HUGE performance boost, it's also nicer to the API.
session = requests.Session()
base_api_url = "https://api.modrinth.com:443/api/v1"
@@ -101,7 +104,7 @@ def getLatestVersion(project, **kwargs):
versions = targetted_versions
else:
versions = getVersions(project)
print(versions)
#print(versions)
publishDates = determine(project, "date_published")
#print(publishDates)
# Get current date
@@ -120,24 +123,53 @@ def getLatestVersion(project, **kwargs):
latest = {key: val for key, val in sorted(shortestDate.items(), key = lambda ele: ele[1])}
return list(latest.keys())[0]
def getLatestStable(project):
print("Calling getLatestStable()...")
versions = getVersions(project)
build_type = determine(project, "version_type")
def key_filter(project, dict_to_filter, key_to_grab, type_to_grab):
print("Calling key_filter()...")
versions = dict_to_filter
build_type = determine(project, key_to_grab)
# Build a dictionary that ties the versions to the build type
build_type_dict = {}
number_of_versions = len(versions)
for item in range(number_of_versions):
build_type_dict[versions[item]] = build_type[item]
print(build_type_dict)
#print(build_type_dict)
# Sort dictionary to filter out only the release builds
stable = []
print("Looking for "+str(type_to_grab))
for key, value in build_type_dict.items():
if value == 'release':
print(key)
#print("looking at "+str(value))
search = re.search(str(type_to_grab), str(value))
if search != None:
print("Match!")
#print(key)
stable.append(key)
# Call getLatestVersion, tell it to use our output
return getLatestVersion(project, targetted_versions=stable)
return stable
def getForMinecraftVersion(project, version, stability):
print("Calling getForMinecraftVersion()...")
print("Downloading",stability,"for Minecraft version", version)
if stability == "stable":
#Filter Game versions
targetted_versions=key_filter(project, getVersions(project), "game_versions", version)
#Filter Stable versions
stable_versions=key_filter(project, targetted_versions, "version_type", "release")
result = getLatestVersion(project, targetted_versions=stable_versions)
elif stability == "latest":
#Filter Game versions
targetted_versions=key_filter(project, getVersions(project), "game_versions", version)
#print(targetted_versions)
#Filter Latest versions
stable_versions=key_filter(project, targetted_versions, "version_type", "release")
result = getLatestVersion(project, targetted_versions=stable_versions)
print("latest build for "+version+" is "+result)
return result
def getLatestStable(project):
print("Calling getLatestStable()...")
return getLatestVersion(project, getVersions(project) ,targetted_versions=key_filter(project, "version_type", "release"))
def getDownloadURL(project, versionID):
print("Calling getDownloadURL()...")