diff --git a/main.py b/main.py index 9f92c5e..41fda75 100644 --- a/main.py +++ b/main.py @@ -28,12 +28,15 @@ def get_files(url: str) -> []: def get_uri(url: str) -> []: if (url in ["/../", "../"]): return ([]) - response = requests.get(url) - # print("connection:", response.reason) - if (response.status_code != 200): - exit - soup = BeautifulSoup(response.text, 'html.parser') - return(soup.find("h1").text[9:]) + try: + response = requests.get(url) + if (response.status_code != 200): + print("connection:", response.reason) + sys.exit(1) + soup = BeautifulSoup(response.text, 'html.parser') + return(soup.find("h1").text[9:]) + except: + return ("") def get(files: [], key: str): names = [] @@ -61,7 +64,11 @@ def files_navigator(): url = url + "/" while True: cookies_table.update(set("last_path", get_uri(url)), query.id == "0") - files = get_files(url) + try: + files = get_files(url) + except: + print("Connection: ERROR") + return (1) terminal_menu = TerminalMenu(get(files, "name"), preview_command=files_preview, preview_size=0.3, show_search_hint=True, title=get_uri(url)) file_choose = terminal_menu.show() if (file_choose == None): @@ -119,8 +126,35 @@ def sites_deleter(): id = int(site_name.split(": ")[0]) sites_table.remove(query.id == id) if (cookies_table.get(query.id == "0").get("last_site") == id): - cookies_table.update(set("last_site", query.id == choose.get("id"))) - cookies_table.update(set("last_path", query.id == choose.get("id"))) + cookies_table.update(set("last_site", ""), query.id == choose.get("id")) + cookies_table.update(set("last_path", ""), query.id == choose.get("id")) + +def sites_editor(): + lst = [] + for i in sites_table.all(): + lst.append(f"{str(i.get('id'))}: {i.get('name')}") + terminal_menu = TerminalMenu(lst, show_search_hint=True, preview_title="delete", preview_command=config_preview) + choose = terminal_menu.show() + if (choose == None): + return (1) + site_name = lst[choose] + id = int(site_name.split(": ")[0]) + site = sites_table.get(query.id == id) + lst = [f"name: {site.get('name')}", f"url: {site.get('url')}", f"user: {site.get('user')}", f"password: {site.get('password')}"] + terminal_menu = TerminalMenu(lst) + choose = terminal_menu.show() + if (choose == None): + return (1); + for i in lst: + print(i); + if (choose == 0): + sites_table.update(set("name", input("name: ")), query.id == id) + elif (choose == 1): + sites_table.update(set("url", input("url: ")), query.id == id) + elif (choose == 2): + sites_table.update(set("user", input("user: ")), query.id == id) + elif (choose == 3): + sites_table.update(set("password", input("password: ")), query.id == id) def sites_navigator(): if (len(sites_table.all()) == 0): @@ -138,7 +172,7 @@ def sites_navigator(): if (choose == len(sites_table.all()) + 1): add_site(); elif (choose == len(sites_table.all()) + 2): - pass + sites_editor() elif (choose == len(sites_table.all()) + 3): sites_deleter() sites_navigator()