added dotenv lib to get from file

This commit is contained in:
death916 2025-12-17 05:09:33 -08:00
parent 97df6d10d7
commit f79c54f993
3 changed files with 36 additions and 5 deletions

View file

@ -6,6 +6,7 @@ readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"bs4>=0.0.2",
"python-dotenv>=1.2.1",
"qbittorrent-api>=2025.11.1",
"requests>=2.32.5",
]

View file

@ -8,6 +8,7 @@ pkgs.mkShell {
python313Packages.uv
python313Packages.ninja
python313Packages.numpy
python313Packages.ipython
bun
];

View file

@ -7,9 +7,10 @@ import random
import re
import time
import qbittorrentapi as qb
import qbittorrentapi as qbapi
import requests
from bs4 import BeautifulSoup
from dotenv import load_dotenv
logging.basicConfig(
level=logging.INFO,
@ -46,7 +47,7 @@ class TorrentScrape:
logging.error(f"Error fetching page: {e}")
return None
def get_episode_info(self):
def get_torrent_link(self):
page = self.get_torrent_page()
if not page:
logging.error("No page found")
@ -100,19 +101,47 @@ class Qbittorrent:
def get_credentials(self):
# Get qbittorrent credentials from .env file
load_dotenv() # gets credentials from env file
self.username = os.getenv("QB_USERNAME")
self.password = os.getenv("QB_PASSWORD")
self.host = os.getenv("QB_HOST")
self.port = os.getenv("QB_PORT")
if not self.username or not self.password:
raise ValueError("QB_USERNAME and QB_PASSWORD must be set in .env file")
def add_torrent(self, link):
# Add torrent to qbittorrent
pass
conn_info = dict(
host=self.host,
port=self.port,
username=self.username,
password=self.password,
)
torrent = qbapi.Client(**conn_info)
try:
torrent.auth_log_in()
logging.info("Logged in to qbittorrent")
except qbapi.LoginFailed:
logging.error("Failed to login to qbittorrent")
raise
except Exception as e:
logging.error(f"Error adding torrent to qbittorrent: {e}")
raise
def main():
qbit = Qbittorrent()
qbit.get_credentials()
qbit.add_torrent(link)
if __name__ == "__main__":
c2c = TorrentScrape()
c2c.get_episode_info()
# c2c.get_torrent_link()
link = c2c.get_torrent_link()
torrent = Qbittorrent()
torrent.get_credentials()
torrent.add_torrent(link)
# Keep main thread alive with minimal resource usage
"""
try: