from request_wrapper import requests_wrapper as requests import re 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 # 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.curseforge.com:443" minecraft_game_id='432' headers = { 'Accept': 'application/json', 'x-api-key': "$2a$10$Sh1qHpOdfdt/XKBbgTDnfeTfoAoNMskMf5smMQc3spQnK27Lmzvsq" } def get_games(): request = session.get(base_api_url+'/v1/games/'+minecraft_game_id, headers = headers) return request.json() def search_mods(searchFilter): request = session.get(base_api_url+"/v1/mods/search", params={'gameId': minecraft_game_id, 'searchFilter': searchFilter}, headers = headers) return request.json() def get_mod(mod_id): request = session.get(base_api_url+'/v1/mods/'+mod_id, headers = headers) return request.json() # This function expects "modInfo" to be a list object def determine(modInfo, whatToDetermine): print("Calling determine()...") numberOfVersions = len(modInfo) determine = [] for item in range(numberOfVersions): workingDict = modInfo[item] determine.append(workingDict[whatToDetermine]) #print(str(item)+" "+str(determine[item])) return determine 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) # 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(): #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 stable def download(mod_id): modInfo = get_mod(mod_id) print(type(modInfo)) modInfoList = [] modInfoList.append(modInfo) data = determine(modInfoList, "data") print(key_filter(modInfo, data, "downloadUrl", ))