core: use simple-term-menu to create menu and fix: file name too long
This commit is contained in:
parent
fd19531ba7
commit
30b3e737ca
41
main.py
41
main.py
@ -2,6 +2,7 @@ from tinydb import TinyDB, Query
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
|
from simple_term_menu import TerminalMenu
|
||||||
|
|
||||||
db = TinyDB("./database.json", indent=4)
|
db = TinyDB("./database.json", indent=4)
|
||||||
query = Query()
|
query = Query()
|
||||||
@ -15,17 +16,17 @@ if (nb_sites == 0):
|
|||||||
site.update({"url": input("url:")})
|
site.update({"url": input("url:")})
|
||||||
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):")})
|
||||||
|
name = input("name[url] :")
|
||||||
|
if (name == ""):
|
||||||
|
name = site.get("url")
|
||||||
|
site.update({"name": name})
|
||||||
sites.insert(site)
|
sites.insert(site)
|
||||||
elif (nb_sites != 1):
|
elif (nb_sites != 1):
|
||||||
for i, site in enumerate(sites.all()):
|
lst = []
|
||||||
print(f"{i}: {site.get('url')}")
|
for site in sites.all():
|
||||||
site_choose = -1
|
append(sites.get("name"))
|
||||||
while (site_choose == -1):
|
terminal_menu = TerminalMenu(lst)
|
||||||
choice = input("what site do you want ?")
|
site_choose = terminal_menu.show()
|
||||||
if ((not choice.isdigit()) or (int(choice) >= nb_sites)):
|
|
||||||
print(f"error: invalid choice, please retry")
|
|
||||||
else:
|
|
||||||
site_choose = int(choice)
|
|
||||||
site = sites.all()[site_choose]
|
site = sites.all()[site_choose]
|
||||||
if (site.get("user") and site.get("password")):
|
if (site.get("user") and site.get("password")):
|
||||||
url = f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}/"
|
url = f"http://{site.get('user')}:{site.get('password')}@{site.get('url')}/"
|
||||||
@ -37,16 +38,12 @@ while True:
|
|||||||
if (response.status_code != 200):
|
if (response.status_code != 200):
|
||||||
exit
|
exit
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
files = soup.findAll("a")
|
lst = []
|
||||||
for i, element in enumerate(files):
|
for element in soup.findAll("a"):
|
||||||
print(f"{i}: {element.text}")
|
lst.append(element.text)
|
||||||
file_choose = -1
|
terminal_menu = TerminalMenu(lst)
|
||||||
while (file_choose == -1):
|
file = soup.findAll("a")[terminal_menu.show()]["href"]
|
||||||
choice = input("what file or folder do you want ?")
|
url = url + file
|
||||||
if ((not choice.isdigit()) or (int(choice) >= len(files))):
|
if (not file.endswith("/")):
|
||||||
print(f"error: invalid choice, please retry")
|
print(f"vlc '{url}'")
|
||||||
else:
|
os.system(f"vlc '{url}'")
|
||||||
file_choose = int(choice)
|
|
||||||
url = url + files[file_choose].text
|
|
||||||
if (not files[file_choose].text.endswith("/")):
|
|
||||||
os.system(f"vlc {url}")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user