New handling system everywhere

This commit is contained in:
BarsTiger
2022-03-01 14:21:42 +02:00
parent a70570225f
commit d35c72bf02
8 changed files with 34 additions and 138 deletions

View File

@@ -3,24 +3,16 @@ import json
import webbrowser
import modules.vars as horsy_vars
from rich import print
from modules.http_status import handle
def get_source(package):
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
try:
r = json.loads(r)
except:
print("[red]Error with unsupported message[/]")
return "Error with unsupported message"
try:
if r["message"] == "not found":
print("[red]Package not found[/]")
return "Package not found"
if r["message"] == "Internal server error":
print("[red]Internal server error[/]")
return "Internal server error"
except:
pass
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}")
r_code = handle(r.status_code)
if r_code[1] not in [200, 201]:
return r_code[1]
r = r.text
r = json.loads(r)
try:
webbrowser.open(r["sourceUrl"])