Skip to content

Commit

Permalink
fix cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
tier940 committed Oct 27, 2023
1 parent a2661f8 commit fe984fa
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions buildtools/mod-install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
import os
import shutil
import requests
import time
from concurrent.futures import ThreadPoolExecutor

## Init
### API
## Initialize
cf_url = "https://api.curseforge.com"
headers = {
"Accept": "application/json",
"x-api-key": os.environ.get("CF_API_TOKEN")
}
tpe = ThreadPoolExecutor(max_workers=20)

### Import List
manifest_json = json.load(open("./manifest.json"))

## Access CF and save file if request succeeds
for key in manifest_json["files"]:
mod_json = requests.get("{}/v1/mods/{}/files/{}".format(
## Run main function
def main(key):
url = "{}/v1/mods/{}/files/{}".format(
cf_url,
key["projectID"],
key["fileID"]
), allow_redirects=True, stream=True, headers=headers)
)
mod_json = requests.get(url, allow_redirects=True, stream=True, headers=headers)

if mod_json.status_code == 200:
mod_json = mod_json.json()
print("{} - {}".format(mod_json["data"]["fileName"], mod_json["data"]["downloadUrl"]))

mod_file = requests.get(mod_json["data"]["downloadUrl"], allow_redirects=True, stream=True, headers=headers)
with open(mod_json["data"]["fileName"], "wb") as f:
shutil.copyfileobj(mod_file.raw, f)
Expand All @@ -47,3 +49,18 @@
os.rename(mod_json["data"]["fileName"], "./overrides/resourcepacks/{}".format(mod_json["data"]["fileName"].replace(".zip", ".zip.disabled")))

print("Downloaded {}".format(mod_json["data"]["fileName"]))
else:
tpe.shutdown()
raise Exception("Status code is not 200 : " + url)


## Import List
manifest_json = json.load(open("./manifest.json"))

## Access CF and save file if request succeeds
for key in manifest_json["files"]:
tpe.submit(main, key)

## Finalize
tpe.shutdown()
print("finished all download.")

0 comments on commit fe984fa

Please sign in to comment.