add: edit menu

This commit is contained in:
starnakin 2023-05-15 21:35:32 +02:00
parent 41f50a05c3
commit 8db47760b3

54
main.py
View File

@ -28,12 +28,15 @@ def get_files(url: str) -> []:
def get_uri(url: str) -> []: def get_uri(url: str) -> []:
if (url in ["/../", "../"]): if (url in ["/../", "../"]):
return ([]) return ([])
response = requests.get(url) try:
# print("connection:", response.reason) response = requests.get(url)
if (response.status_code != 200): if (response.status_code != 200):
exit print("connection:", response.reason)
soup = BeautifulSoup(response.text, 'html.parser') sys.exit(1)
return(soup.find("h1").text[9:]) soup = BeautifulSoup(response.text, 'html.parser')
return(soup.find("h1").text[9:])
except:
return ("")
def get(files: [], key: str): def get(files: [], key: str):
names = [] names = []
@ -61,7 +64,11 @@ def files_navigator():
url = url + "/" url = url + "/"
while True: while True:
cookies_table.update(set("last_path", get_uri(url)), query.id == "0") 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)) 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() file_choose = terminal_menu.show()
if (file_choose == None): if (file_choose == None):
@ -119,8 +126,35 @@ def sites_deleter():
id = int(site_name.split(": ")[0]) id = int(site_name.split(": ")[0])
sites_table.remove(query.id == id) sites_table.remove(query.id == id)
if (cookies_table.get(query.id == "0").get("last_site") == 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_site", ""), query.id == choose.get("id"))
cookies_table.update(set("last_path", 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(): def sites_navigator():
if (len(sites_table.all()) == 0): if (len(sites_table.all()) == 0):
@ -138,7 +172,7 @@ def sites_navigator():
if (choose == len(sites_table.all()) + 1): if (choose == len(sites_table.all()) + 1):
add_site(); add_site();
elif (choose == len(sites_table.all()) + 2): elif (choose == len(sites_table.all()) + 2):
pass sites_editor()
elif (choose == len(sites_table.all()) + 3): elif (choose == len(sites_table.all()) + 3):
sites_deleter() sites_deleter()
sites_navigator() sites_navigator()