def test_log_in(): client_good = Client() client_bad = Client(username='******', password='******') assert client_good.auth_log_in() is None with pytest.raises(LoginFailed): client_bad.auth_log_in()
def test_log_in(): client_good = Client(VERIFY_WEBUI_CERTIFICATE=False) client_bad = Client( username="******", password="******", VERIFY_WEBUI_CERTIFICATE=False ) assert client_good.auth_log_in() is None with pytest.raises(LoginFailed): client_bad.auth_log_in()
def test_log_in_via_auth(): client_good = Client() client_bad = Client(username='******', password='******') assert client_good.auth_log_in( username=environ.get('PYTHON_QBITTORRENTAPI_USERNAME'), password=environ.get('PYTHON_QBITTORRENTAPI_PASSWORD')) is None with pytest.raises(LoginFailed): client_bad.auth_log_in(username='******', password='******')
def client(): """qBittorrent Client for testing session""" try: client = Client(RAISE_NOTIMPLEMENTEDERROR_FOR_UNIMPLEMENTED_API_ENDPOINTS=True, VERBOSE_RESPONSE_LOGGING=True) client.auth_log_in() # add orig_torrent to qBittorrent client.torrents_add(urls=_orig_torrent_url, upload_limit=10, download_limit=10) return client except APIConnectionError: pytest.exit('qBittorrent was not running when tests started')
def test_log_in_via_auth(): client_good = Client(VERIFY_WEBUI_CERTIFICATE=False) client_bad = Client(username="******", password="******", VERIFY_WEBUI_CERTIFICATE=False) assert (client_good.auth_log_in( username=environ.get("PYTHON_QBITTORRENTAPI_USERNAME"), password=environ.get("PYTHON_QBITTORRENTAPI_PASSWORD"), ) is None) with pytest.raises(exceptions.LoginFailed): client_bad.auth_log_in(username="******", password="******")
def test_log_in(): client_good = Client(VERIFY_WEBUI_CERTIFICATE=False) client_bad = Client(username="******", password="******", VERIFY_WEBUI_CERTIFICATE=False) client_good.auth_log_out() assert client_good.auth_log_in() is None assert client_good.is_logged_in is True client_good.auth_log_out() assert client_good.auth.log_in() is None assert client_good.auth.is_logged_in is True assert client_good.auth.is_logged_in is True with pytest.raises(exceptions.LoginFailed): client_bad.auth_log_in() with pytest.raises(exceptions.LoginFailed): client_bad.auth.log_in()
def client(): """qBittorrent Client for testing session""" try: client = Client( RAISE_NOTIMPLEMENTEDERROR_FOR_UNIMPLEMENTED_API_ENDPOINTS=True, VERBOSE_RESPONSE_LOGGING=True, VERIFY_WEBUI_CERTIFICATE=False, ) client.auth_log_in() # add orig_torrent to qBittorrent client.torrents_add(urls=_orig_torrent_url, upload_limit=10, download_limit=10) # enable RSS fetching client.app.preferences = dict(rss_processing_enabled=True) return client except APIConnectionError as e: pytest.exit("qBittorrent was not running when tests started: %s" % repr(e))
def get_client(self): """ Returns a client to qbittorrent """ client = Client(host=self.host, port=self.port, username=self.user, password=self.password) try: client.auth_log_in() LOGGER.info("Successfully connected to qbittorrent") except exceptions.LoginFailed as login_exn: LOGGER.error("Failed to login to qbittorrent") raise QbitError except exceptions.Forbidden403Error as forbid_exn: LOGGER.error("403 error on qbittorrent") raise QbitError except exceptions.APIConnectionError: LOGGER.error("Failed to connect to Qbittorrent") raise QbitError return client
class qbittorrent_alternative_speed(SwitchEntity): def __init__(self, host, username, password, name): self.host = host self.username = username self.password = password self._name = name self.qb = Client(host=self.host, username=self.username, password=self.password) self.signin() def signin(self): self.qb.auth_log_in() self._state = int(self.qb.transfer.speed_limits_mode) @property def name(self): return self._name @property def is_on(self): return (self._state == 1) def update(self): try: self._state = int(self.qb.transfer.speed_limits_mode) except: self.signin() return def turn_on(self): self.update() if (self._state == 0): self.qb.transfer.toggle_speed_limits_mode() def turn_off(self): self.update() if (self._state == 1): self.qb.transfer.toggle_speed_limits_mode()
import requests from bs4 import BeautifulSoup as bs from qbittorrentapi import Client import os qb = Client("http://127.0.0.1:8080") qb.auth_log_in("admin", "adminadmin") ctr = 80 href2 = "" select = "div.list-board > ul > li > div.wr-subject.ellipsis > a" select2 = "div.view-padding > div.view-torrent > table > thead > tr > th > strong" analized = open("analized.txt", 'a') def download(url, file_name): with open(file_name, "wb") as file: # open in binary mode response = requests.get(url) # get request file.write(response.content) # write to file def download_torrent(main, ctr): main = main + str(ctr) req = requests.get(main) html = req.text soup = bs(html, 'html.parser') href = soup.find_all("a", class_="font-13 en") for a in href: url = a.attrs['href'] req = requests.get(url) if req.status_code != 200: