cleaned up code + better handling for no results
This commit is contained in:
@@ -13,20 +13,14 @@ input_name = input("Enter modpack name: ")
|
|||||||
response = requests.get(f'https://api.curseforge.com/v1/mods/search?gameId=432&searchFilter={input_name}', headers=headers)
|
response = requests.get(f'https://api.curseforge.com/v1/mods/search?gameId=432&searchFilter={input_name}', headers=headers)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
modpack_name = {}
|
|
||||||
modpack_id = {}
|
|
||||||
url_dict = {}
|
|
||||||
found = False
|
found = False
|
||||||
|
selected_modpack_id = -1
|
||||||
|
|
||||||
modpack_names = []
|
modpack_names = []
|
||||||
for mod in data['data']:
|
for mod in data['data']:
|
||||||
modpack_url = mod['links']['websiteUrl']
|
modpack_url = mod['links']['websiteUrl']
|
||||||
if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"):
|
if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"):
|
||||||
modpack_names.append(mod['name'])
|
modpack_names.append(mod['name'])
|
||||||
# modpack_id = mod['id']
|
|
||||||
# modpack_name = mod['name']
|
|
||||||
# url_dict[mod['links']['websiteUrl']] = modpack_url + str(modpack_id) + modpack_name
|
|
||||||
# modpack = f"{modpack_name} {modpack_id} {url_dict}"
|
|
||||||
found = True
|
found = True
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@@ -36,39 +30,27 @@ if not found:
|
|||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
questions = [
|
if found == True:
|
||||||
|
questions = [
|
||||||
inquirer.List('name',
|
inquirer.List('name',
|
||||||
message="Select a modpack",
|
message="Select a modpack",
|
||||||
choices=modpack_names,
|
choices=modpack_names,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
answers = inquirer.prompt(questions)
|
answers = inquirer.prompt(questions)
|
||||||
|
|
||||||
selected_modpack_id = -1
|
selected_modpack_name = answers['name']
|
||||||
|
for mod in data['data']:
|
||||||
selected_modpack_name = answers['name']
|
|
||||||
# get modpack id from selected modpack name
|
|
||||||
for mod in data['data']:
|
|
||||||
if mod['name'] == selected_modpack_name:
|
if mod['name'] == selected_modpack_name:
|
||||||
selected_modpack_id = mod['id']
|
selected_modpack_id = mod['id']
|
||||||
selected_url = mod['links']['websiteUrl']
|
selected_url = mod['links']['websiteUrl']
|
||||||
|
|
||||||
print(selected_modpack_id)
|
r = requests.get(f"https://api.curseforge.com/v1/mods/{selected_modpack_id}/files", headers = headers)
|
||||||
|
file_data = r.json()
|
||||||
|
print(file_data)
|
||||||
r = requests.get(f"https://api.curseforge.com/v1/mods/{selected_modpack_id}/files", headers = headers)
|
for file in file_data['data']:
|
||||||
file_data = r.json()
|
|
||||||
print(file_data)
|
|
||||||
for file in file_data['data']:
|
|
||||||
# server_file = file['isServerPack']
|
|
||||||
server_file = file['serverPackFileId']
|
server_file = file['serverPackFileId']
|
||||||
print (server_file)
|
print (server_file)
|
||||||
else:
|
else:
|
||||||
print("No server pack found for this modpack.")
|
print("No server pack found for this modpack.")
|
||||||
|
|
||||||
# if answers is None:
|
|
||||||
# print("No selection made.")
|
|
||||||
# else:
|
|
||||||
# selected_url = answers['url']
|
|
||||||
# print(f"You selected: {selected_url}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user