4
1
Fork 1
This repository has been archived on 2024-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
qBitDownload-Bot/func.py

79 lines
1.9 KiB
Python
Raw Normal View History

2023-10-30 22:02:43 +00:00
#!/usr/bin/python3
# -- coding: utf-8 --
import db, os, subprocess
from db import *
def u_auth(id,passwd):
list = []
if db.check('obj',AUTH_FILE):
list = db.read(AUTH_FILE)
if id in list:
return 'You already logged in'
else:
if passwd == os.environ['PASS']:
list.append(id)
db.write(list,AUTH_FILE)
return 'Success'
else:
return 'Wrong password'
def auth_check(id):
if db.check('obj',AUTH_FILE):
list = db.read(AUTH_FILE)
else:
list = []
if id in list:
return True
def add_dir(id,dir,path):
if auth_check(id):
if os.path.exists(path) == False:
return 'Folder not exist on host'
if db.check('obj',DIR_FILE):
dict = db.read(DIR_FILE)
else:
dict = {}
dict.setdefault(dir,path)
db.write(dict,DIR_FILE)
return 'Success'
else:
return 'Log in first'
def del_dir(id,dir):
if auth_check(id):
if db.check('obj',DIR_FILE):
dict = db.read(DIR_FILE)
else:
dict = {}
if dir in dict:
del dict[dir]
db.write(dict,DIR_FILE)
return 'Success'
else:
return 'Dir not exists'
else:
return 'Log in first'
def magnet(id,link,dir):
if auth_check(id):
2023-10-30 23:03:14 +00:00
dict = db.read(DIR_FILE)
path = dict[dir]
command = f'''qbt torrent add url "{link} -f {path}"'''
os.system(f"bash -c '{command}'")
2023-10-30 22:02:43 +00:00
return 'Success'
2023-10-30 23:03:14 +00:00
else:
return 'Log in first'
2023-10-30 22:02:43 +00:00
def file(id,file,dir):
if auth_check(id):
subprocess.run(f"qbt torrent add file {PATH}{file} -f {dir}", check=True, shell=True)
os.remove(f'{PATH}{file}')
return 'Success'
def dirlist():
dirs = {}
if db.check('obj',DIR_FILE):
dirs = db.read(DIR_FILE)
return dirs