Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration of AddqBittorrentTrackers to Python version #1

Open
Jorman opened this issue Aug 19, 2024 · 8 comments
Open

Migration of AddqBittorrentTrackers to Python version #1

Jorman opened this issue Aug 19, 2024 · 8 comments

Comments

@Jorman
Copy link

Jorman commented Aug 19, 2024

Ciao, here we go!
Any idea to start? Ok, from here but how to set up the work?

@ineednewpajamas
Copy link
Owner

Check out https://docs.python.org/3/library/venv.html

I'll commit what I have so far into a branch

@ineednewpajamas
Copy link
Owner

Here is an example of like a super simple script that just checks that connection status of qbit and sends me an apprise notification if its not connected. You do have to install qbittorrent-api but its easy to do in the venv and then you just keep using that venv going forward.

#!/usr/bin/python3
import qbittorrentapi # type: ignore
import requests       # type: ignore

# instantiate a Client using the appropriate WebUI configuration
conn_info = dict(
    host="qbittorrent",
    port=8080,
    username="",
    password="",
)
qbt_client = qbittorrentapi.Client(**conn_info)

def send_apprise( msg, tag ):
    url = 'http://apprise:8000/notify/default'
    requests.post(
        url,
        files=(
            ('body', (None, msg)),
            ('tags', (None, tag)),
        )
    )

# the Client will automatically acquire/maintain a logged-in state
# in line with any request. therefore, this is not strictly necessary;
# however, you may want to test the provided login credentials.
try:
    qbt_client.auth_log_in()
except qbittorrentapi.LoginFailed as e:
    print(e)

transfer_info = qbt_client.transfer_info()
if transfer_info.connection_status != "connected":
    print("Not Connected")
    send_apprise(f"qBit has a status of {transfer_info.connection_status}", "healthchecks")

@ineednewpajamas
Copy link
Owner

#2

@Jorman
Copy link
Author

Jorman commented Aug 19, 2024

Yep, I know venv, already used it, but only to run projects that are not mine, maybe I don't know it well as it is explained in the pages you listed, I have always used it in a very basic way, as I told you I am not a big python expert. as a start we can I would say it is ok. any ideas? How does the python logic work? This is where I get into difficulty!

@ineednewpajamas
Copy link
Owner

Which logic?

@Jorman
Copy link
Author

Jorman commented Aug 20, 2024

I mean the bash file, it starts with the first if and continues to the end, with python instead? Do you do a single try except? with everything in it? What about options for manual execution?

@ineednewpajamas
Copy link
Owner

check out the latest commit on the pr, the main function will have the bulk of the logic, and argparse will allow for arguments but the defaults will be whats at the very top of the script if nothing is passed in. Been busy so haven't made much progress and I'm really just going line by line for now so i'll see how far I get with that

@Jorman
Copy link
Author

Jorman commented Sep 10, 2024

Ciao, quiet no problem, I've been busy too, these days I'll look and try to understand the logic too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants