Archived

This topic is now archived and is closed to further replies.

EdwardGrey

Python Script - Ignore Lables

Recommended Posts

Hello all,

I've been using the following Python script to automatically remove completed torrents using the WebUI:

import requests

# set variables to connect to uTorrent web UI
port = 8080
username = 'username'
password = 'password'

# set action urls
list_url = "http://192.168.1.1:{port}/gui/?list=1".format(port=port)
remove_url = "http://192.168.1.1:{port}/gui/?action=remove&hash={match}"

# open URL to get data
r = requests.get(list_url, auth=(username, password))

# return json object using 'torrents' index to narrow object to just torrents
json_obj = r.json()['torrents']

# for each torrent in the json object, check if it is finished and delete if so
for torrent in json_obj:
    finished_parse = str(torrent).find("100.0 %")
    if finished_parse != -1:
        match = torrent[0].strip("'")
        if match:
            remove = requests.get(remove_url.format(port=port, match=match),
                                  auth=(username, password))

I was hoping to modify it to ignore torrents with specific labels, but my Python skills are woefully lacking.  Does anyone have any insight into how this to could be updated to accomplish that task?

Thank you in advance.

Share this post


Link to post
Share on other sites

This should do the trick.
 

import requests

# set variables to connect to uTorrent web UI
port = 8080
username = 'username'
password = 'password'

# set action urls
list_url = "http://192.168.1.1:{port}/gui/?list=1".format(port=port)
remove_url = "http://192.168.1.1:{port}/gui/?action=remove&hash={match}"

# open URL to get data
r = requests.get(list_url, auth=(username, password))

# return json object using 'torrents' index to narrow object to just torrents
json_obj = r.json()['torrents']

# for each torrent in the json object, check if it is finished and delete if so
for torrent in json_obj:
    finished_parse = str(torrent).find("100.0 %")
    if finished_parse != -1:
        label = torrent[11].strip("'")
        if label == "Label1" or label == "Label2" or label == "Label3"
            match = false
        else
            match = torrent[0].strip("'")
        if match:
            remove = requests.get(remove_url.format(port=port, match=match),
                                  auth=(username, password))

 

Share this post


Link to post
Share on other sites