Improve structure in main.py, create requirements.txt and update README.

This commit is contained in:
Vxrtrauter
2025-10-12 04:03:45 +02:00
parent 5c58d5c6ac
commit f67190296f
3 changed files with 78 additions and 28 deletions
+47 -23
View File
@@ -10,42 +10,53 @@ headers = {
'x-api-key': os.getenv("CURSEFORGE_API_KEY")
}
input_name = input("Enter modpack name: ")
response = requests.get(f'https://api.curseforge.com/v1/mods/search?gameId=432&searchFilter={input_name}', headers=headers)
data = response.json()
modpack_names = []
found = False
selected_modpack_id = -1
modpack_names = []
for mod in data['data']:
modpack_url = mod['links']['websiteUrl']
if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"):
modpack_names.append(mod['name'])
found = True
else:
pass
if not found:
print("No modpack found with that name.")
else:
pass
def search_modpacks(query):
global data
global found
if found == True:
questions = [
inquirer.List('name',
message="Select a modpack",
choices=modpack_names,
),
]
response = requests.get(f'https://api.curseforge.com/v1/mods/search?gameId=432&searchFilter={query}', headers=headers)
data = response.json()
for mod in data['data']:
modpack_url = mod['links']['websiteUrl']
if modpack_url.startswith("https://www.curseforge.com/minecraft/modpacks/"):
modpack_names.append(mod['name'])
found = True
if not found:
print("No modpack found with that name.")
return modpack_names
def select_modpacks(modpack_names):
if found == True:
questions = [
inquirer.List('name',
message="Select a modpack",
choices=modpack_names
),
]
answers = inquirer.prompt(questions)
selected_modpack_name = answers['name']
for mod in data['data']:
if mod['name'] == selected_modpack_name:
selected_modpack_id = mod['id']
selected_url = mod['links']['websiteUrl']
return selected_modpack_name, selected_modpack_id
def download_modpack(selected_modpack_name, selected_modpack_id):
r = requests.get(f"https://api.curseforge.com/v1/mods/{selected_modpack_id}/files", headers = headers)
file_data = r.json()
@@ -66,3 +77,16 @@ if found == True:
break
else:
print("No server pack found for this modpack.")
if __name__ == "__main__":
print("Serverpack Downloader")
query = input("Enter Search Query: ")
modpack_names = search_modpacks(query)
selected_modpack_name, selected_modpack_id = select_modpacks(modpack_names)
download_modpack(selected_modpack_name, selected_modpack_id)