Search and info
This commit is contained in:
@@ -11,15 +11,15 @@ from modules.virustotal import get_key, scan_file, get_report
|
||||
|
||||
def install(package, is_gui=False):
|
||||
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
|
||||
if r == "":
|
||||
print(f"[red]Package {package} not found[/]")
|
||||
return
|
||||
try:
|
||||
r = json.loads(r)
|
||||
except:
|
||||
print("[red]Error with unsupported message[/]")
|
||||
return
|
||||
try:
|
||||
if r["message"] == "not found":
|
||||
print("[red]Package not found[/]")
|
||||
return
|
||||
if r["message"] == "Internal server error":
|
||||
print("[red]Internal server error[/]")
|
||||
return
|
||||
@@ -55,7 +55,8 @@ def install(package, is_gui=False):
|
||||
f"[italic white] in terminal[/]")
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
||||
print(f"[green]Virustotal scan finished[/]")
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1],
|
||||
horsy_vars.horsypath))
|
||||
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
||||
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
||||
|
||||
@@ -78,8 +79,8 @@ def install(package, is_gui=False):
|
||||
|
||||
chunk_size = 1024
|
||||
file_r = requests.get(r['download'], stream=True)
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath), "wb") \
|
||||
as f:
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
|
||||
"wb") as f:
|
||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
@@ -120,7 +121,7 @@ def install(package, is_gui=False):
|
||||
|
||||
except:
|
||||
print("[red]Unexpected error[/]")
|
||||
raise
|
||||
# raise
|
||||
return
|
||||
|
||||
|
||||
|
||||
49
modules/search.py
Normal file
49
modules/search.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import textwrap
|
||||
from algoliasearch.search_client import SearchClient
|
||||
import os
|
||||
import requests
|
||||
import modules.vars as horsy_vars
|
||||
import json
|
||||
from rich import print
|
||||
|
||||
|
||||
client = SearchClient.create('VBUJO9OW62', '759f6c7986842fd8218e79e3b9ddb964')
|
||||
index = client.init_index('packages')
|
||||
|
||||
|
||||
def search(query):
|
||||
res = index.search(query)['hits']
|
||||
for i in res:
|
||||
print(textwrap.shorten(f"{i['name']} by {i['authorName']} - {i['description']}",
|
||||
width=os.get_terminal_size().columns))
|
||||
|
||||
|
||||
def info(package):
|
||||
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
|
||||
if r == "":
|
||||
print(f"[red]Package {package} not found[/]")
|
||||
return
|
||||
try:
|
||||
r = json.loads(r)
|
||||
except:
|
||||
print("[red]Error with unsupported message[/]")
|
||||
return
|
||||
try:
|
||||
if r["message"] == "Internal server error":
|
||||
print("[red]Internal server error[/]")
|
||||
return
|
||||
except:
|
||||
pass
|
||||
|
||||
print(f"[bold]{r['name']}{'✅' if r['verified'] else ''} by {r['authorName']}[/]")
|
||||
print(f"{r['description']}")
|
||||
print(f"👍{r['likes']} | 👎{r['dislikes']}")
|
||||
if not r['verified']:
|
||||
print("This package is not verified by the horsy team. This means that it \n"
|
||||
"can be unstable or it can be malware. Most packages have unverified\n"
|
||||
"state, but use it at your own risk.")
|
||||
else:
|
||||
print("This package is [green]verified[/] by the horsy team! \n"
|
||||
"Keep in mind, developers can change the code after verification \n"
|
||||
"We [red]don't call you to trust this app[/], use it at your own risk \n"
|
||||
"but we recommend you more to install verified packages")
|
||||
Reference in New Issue
Block a user