Initial modpack installation implementation

This commit is contained in:
Евгений Титаренко 2023-01-10 22:55:42 +03:00
parent 1e923dacb9
commit 983d0f9e21
4 changed files with 117 additions and 52 deletions

28
api.py
View file

@ -1,22 +1,22 @@
#from objects.api-objects import *
import requests
from tqdm import tqdm
import json
API_VERSION = "v2"
HEADERS = {
'User-Agent': 'mc-get-testing'
}
def download(file_url:str, file_size:int, path:str):
def download(file_url: str, file_size: int, path: str):
resp = requests.get(file_url, stream=True, headers=HEADERS)
with open(path,'wb') as file:
for data in tqdm(resp.iter_content(), total=file_size,\
unit_scale=True, unit="byte"):
with open(path, 'wb') as file:
for data in tqdm(resp.iter_content(), total=file_size, unit_scale=True, unit="byte"):
file.write(data)
def __method(method:str, api_version:str=API_VERSION):
def __method(method: str, api_version: str = API_VERSION):
api_url = "https://api.modrinth.com"
def request(**args):
sub_method = ""
if "project" in args:
@ -24,21 +24,19 @@ def __method(method:str, api_version:str=API_VERSION):
elif "version" in args:
sub_method = "/" + args.pop("version")
print(f"{api_url}/{api_version}{method}{sub_method}")
resp = requests.get(f"{api_url}/{api_version}{method}{sub_method}",\
params=args, headers=HEADERS)
print(resp.headers.get("X-Ratelimit-Remaining",-1))
resp = requests.get(f"{api_url}/{api_version}{method}{sub_method}", params=args, headers=HEADERS)
print(resp.headers.get("X-Ratelimit-Remaining", -1))
match resp.status_code:
case 200:
print("200: OK")
if type(resp.json()) == list:
return [type(method, (object,), obj)\
for obj in resp.json()]
return [type(method, (object,), obj) for obj in resp.json()]
return type(method, (object,), resp.json())
case 400:
#invalid request
# Invalid request
print("400: ERROR")
case 401:
# No autorization
# No authorization
print("401: ERROR")
case 404:
'''
@ -49,9 +47,9 @@ def __method(method:str, api_version:str=API_VERSION):
resp.raise_for_status()
return request
test = __method("", "")
search = __method("/search")
project = __method("/project")
version = __method("/version")
versions = __method("/versions")