fix: and clean
This commit is contained in:
parent
d39e9cfb62
commit
61f535fce4
37
main.py
37
main.py
@ -24,8 +24,8 @@ def files_navigator(site: dict):
|
|||||||
else:
|
else:
|
||||||
path = path + file
|
path = path + file
|
||||||
|
|
||||||
def add_site():
|
def add_site(database: Database):
|
||||||
site = menu.add_site()
|
site = menu.add_site(database)
|
||||||
database.add_site(site)
|
database.add_site(site)
|
||||||
|
|
||||||
def config_preview(site_name:str):
|
def config_preview(site_name:str):
|
||||||
@ -38,12 +38,11 @@ def config_preview(site_name:str):
|
|||||||
"""
|
"""
|
||||||
return (str)
|
return (str)
|
||||||
|
|
||||||
def sites_deleter():
|
def sites_deleter(database: Database):
|
||||||
lst = []
|
lst = []
|
||||||
for i in sites_table.all():
|
for i in database.get_sites():
|
||||||
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
|
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 = menu.site_deleter(lst, database)
|
||||||
choose = terminal_menu.show()
|
|
||||||
if (choose == None):
|
if (choose == None):
|
||||||
return (1)
|
return (1)
|
||||||
site_name = lst[choose]
|
site_name = lst[choose]
|
||||||
@ -53,20 +52,18 @@ def sites_deleter():
|
|||||||
database.set_last_path("")
|
database.set_last_path("")
|
||||||
database.set_last_site("")
|
database.set_last_site("")
|
||||||
|
|
||||||
def sites_editor(site_id: int):
|
def sites_editor(database: Database):
|
||||||
lst = []
|
lst = []
|
||||||
for i in database.get_sites():
|
for i in database.get_sites():
|
||||||
lst.append(f"{str(i.get('id'))}: {i.get('name')}")
|
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 = menu.site_editor(lst, database)
|
||||||
choose = terminal_menu.show()
|
|
||||||
if (choose == None):
|
if (choose == None):
|
||||||
return (1)
|
return (1)
|
||||||
site_name = lst[choose]
|
site_name = lst[choose]
|
||||||
id = int(site_name.split(": ")[0])
|
id = int(site_name.split(": ")[0])
|
||||||
site = database.get_site_by_id(id)
|
site = database.get_site_by_id(id)
|
||||||
lst = [f"name: {site.get('name')}", f"url: {site.get('url')}", f"user: {site.get('user')}", f"password: {site.get('password')}"]
|
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 = menu.param_editor(lst)
|
||||||
choose = terminal_menu.show()
|
|
||||||
if (choose == None):
|
if (choose == None):
|
||||||
return (1);
|
return (1);
|
||||||
for i in lst:
|
for i in lst:
|
||||||
@ -80,7 +77,7 @@ def sites_editor(site_id: int):
|
|||||||
elif (choose == 3):
|
elif (choose == 3):
|
||||||
sites_table.update(set("password", input("password: ")), query.id == id)
|
sites_table.update(set("password", input("password: ")), query.id == id)
|
||||||
|
|
||||||
def sites_navigator():
|
def sites_navigator(database: Database):
|
||||||
nb_site = database.get_sites_table_len()
|
nb_site = database.get_sites_table_len()
|
||||||
if (nb_site == 0):
|
if (nb_site == 0):
|
||||||
add_site()
|
add_site()
|
||||||
@ -90,24 +87,22 @@ def sites_navigator():
|
|||||||
files_navigator(last_site)
|
files_navigator(last_site)
|
||||||
while True:
|
while True:
|
||||||
nb_site = database.get_sites_table_len()
|
nb_site = database.get_sites_table_len()
|
||||||
terminal_menu = TerminalMenu(get(database.get_sites(), "name") + ["", "add", "edit", "delete"], skip_empty_entries=True, show_search_hint=True)
|
choose = menu.sites(database.get_sites())
|
||||||
choose = terminal_menu.show()
|
|
||||||
if (choose == None):
|
if (choose == None):
|
||||||
return (1)
|
return (1)
|
||||||
if (choose == nb_site + 1):
|
if (choose == nb_site + 1):
|
||||||
add_site();
|
add_site(database);
|
||||||
elif (choose == nb_site + 2):
|
elif (choose == nb_site + 2):
|
||||||
sites_editor()
|
sites_editor(database)
|
||||||
elif (choose == nb_site + 3):
|
elif (choose == nb_site + 3):
|
||||||
sites_deleter()
|
sites_deleter(database)
|
||||||
sites_navigator()
|
sites_navigator(database)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
set_url(database.get_sites()[choose])
|
files_navigator(database.get_sites()[choose])
|
||||||
files_navigator()
|
|
||||||
|
|
||||||
database = Database()
|
database = Database()
|
||||||
|
|
||||||
if (database.get_cookies_table_len() == 0):
|
if (database.get_cookies_table_len() == 0):
|
||||||
database.add_cookies({"last_path": "", "last_site": "", "id": "0"})
|
database.add_cookies({"last_path": "", "last_site": "", "id": "0"})
|
||||||
sites_navigator();
|
sites_navigator(database);
|
||||||
|
38
menu.py
38
menu.py
@ -1,10 +1,11 @@
|
|||||||
from simple_term_menu import TerminalMenu
|
from simple_term_menu import TerminalMenu
|
||||||
from database import Database
|
from database import Database
|
||||||
from scrapper import get_files, get_uri
|
from scrapper import get_files, get_uri
|
||||||
from utils import get_url
|
from utils import get_url, get
|
||||||
|
|
||||||
uri = ""
|
uri = ""
|
||||||
preview_site = {}
|
preview_site = {}
|
||||||
|
preview_database = ""
|
||||||
|
|
||||||
def add_site(database: Database) -> dict:
|
def add_site(database: Database) -> dict:
|
||||||
print("add a site:")
|
print("add a site:")
|
||||||
@ -12,10 +13,10 @@ def add_site(database: Database) -> dict:
|
|||||||
site.update({"url": input("url without protocol (ip:port):")})
|
site.update({"url": input("url without protocol (ip:port):")})
|
||||||
site.update({"user": input("user(leave blank):")})
|
site.update({"user": input("user(leave blank):")})
|
||||||
site.update({"password": input("password(leave blank):")})
|
site.update({"password": input("password(leave blank):")})
|
||||||
site.update({"id": str(database.get_sites_table_len())})
|
site.update({"id": database.get_sites_table_len()})
|
||||||
name = input(f"name[{str(len(sites_table.all()))}] :")
|
name = input(f"name[{str(database.get_sites_table_len())}]")
|
||||||
if (name == ""):
|
if (name == ""):
|
||||||
name = str(database.get_sites_table_len())
|
name = database.get_sites_table_len()
|
||||||
site.update({"name": name})
|
site.update({"name": name})
|
||||||
return (site)
|
return (site)
|
||||||
|
|
||||||
@ -38,11 +39,15 @@ def files(site, path):
|
|||||||
show_search_hint=True,
|
show_search_hint=True,
|
||||||
title=f"Index of {path}")
|
title=f"Index of {path}")
|
||||||
choose = terminal_menu.show()
|
choose = terminal_menu.show()
|
||||||
|
if (choose == None):
|
||||||
|
return (None)
|
||||||
return (files[choose])
|
return (files[choose])
|
||||||
|
|
||||||
def config_preview(site_name:str):
|
def config_preview(site_name:str):
|
||||||
id = int(site_name.split(": ")[0])
|
id = int(site_name.split(": ")[0])
|
||||||
site = database.get_site_by_id(id)
|
site = preview_database.get_site_by_id(id)
|
||||||
|
if (site == None):
|
||||||
|
return
|
||||||
str = f"""
|
str = f"""
|
||||||
url: {site.get('url')}
|
url: {site.get('url')}
|
||||||
user: {site.get('user')}
|
user: {site.get('user')}
|
||||||
@ -50,7 +55,10 @@ def config_preview(site_name:str):
|
|||||||
"""
|
"""
|
||||||
return (str)
|
return (str)
|
||||||
|
|
||||||
def site_deleter(sites: list):
|
def site_deleter(sites, database: Database):
|
||||||
|
global preview_database
|
||||||
|
|
||||||
|
preview_database = database
|
||||||
terminal_menu = TerminalMenu(sites,
|
terminal_menu = TerminalMenu(sites,
|
||||||
show_search_hint=True,
|
show_search_hint=True,
|
||||||
preview_title="delete",
|
preview_title="delete",
|
||||||
@ -58,7 +66,15 @@ def site_deleter(sites: list):
|
|||||||
choose = terminal_menu.show()
|
choose = terminal_menu.show()
|
||||||
return (choose)
|
return (choose)
|
||||||
|
|
||||||
def site_editor(lst: list):
|
def param_editor(lst: list):
|
||||||
|
terminal_menu = TerminalMenu(lst)
|
||||||
|
choose = terminal_menu.show()
|
||||||
|
return (choose)
|
||||||
|
|
||||||
|
def site_editor(lst: list, database: Database):
|
||||||
|
global preview_database
|
||||||
|
|
||||||
|
preview_database = database
|
||||||
terminal_menu = TerminalMenu(lst + ["", "quit"],
|
terminal_menu = TerminalMenu(lst + ["", "quit"],
|
||||||
skip_empty_entries=True,
|
skip_empty_entries=True,
|
||||||
show_search_hint=True,
|
show_search_hint=True,
|
||||||
@ -68,3 +84,11 @@ def site_editor(lst: list):
|
|||||||
if (choose == len(lst) + 1):
|
if (choose == len(lst) + 1):
|
||||||
return (None)
|
return (None)
|
||||||
return (choose)
|
return (choose)
|
||||||
|
|
||||||
|
def sites(sites: list):
|
||||||
|
nb_site = len(sites)
|
||||||
|
terminal_menu = TerminalMenu(get(sites, "name") + ["", "add", "edit", "delete"],
|
||||||
|
skip_empty_entries=True,
|
||||||
|
show_search_hint=True)
|
||||||
|
choose = terminal_menu.show()
|
||||||
|
return (choose)
|
||||||
|
6
utils.py
6
utils.py
@ -4,3 +4,9 @@ def get_url(site: dict):
|
|||||||
return (f"http://{site.get('url')}")
|
return (f"http://{site.get('url')}")
|
||||||
else:
|
else:
|
||||||
return (f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}")
|
return (f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}")
|
||||||
|
|
||||||
|
def get(dictionnarys: list, key: str):
|
||||||
|
lst = []
|
||||||
|
for dictionnary in dictionnarys:
|
||||||
|
lst.append(dictionnary.get(key))
|
||||||
|
return (lst)
|
||||||
|
Loading…
Reference in New Issue
Block a user