<commit_before>import os
import string

from deluge.ui.client import client
from deluge.error import InvalidTorrentError


class Monitor(object):

    def __init__(self):
        self.trackerlist = {"animebyt.es", "bakabt.me",
                            "bitgamer.su", "speed.cd", "what.cd"}
        self.torrentlist = []

    def addTorrent(self, torrent_id):
        self.torrentlist.append(torrent_id)

    def cleanTorrents(self):
        if self.torrentlist:
            for i in self.torrentlist:
                torrent_id = i
                status = client.core.get_torrent_status(torrent_id, ['tracker_host', 'ratio', 'active_time', 'progress'])
                status.addCallback(cleanUp, torrent_id)


def cleanUp(status, torrent_id):
    print status
    privatetracker = False
    for j in self.trackerlist:
        if status['tracker_host'] == j:
            privatetracker = True
            break

    #if ((status['progress'] == 1.0 and
    #        status['ratio'] >= 1.0 and not privatetracker) or (status['progress'] == 1.0 and status['active_time'] == 10 and not privatetracker)):
    if status['progress'] == 1:
        try:
            client.core.remove_torrent(torrent_id,
                                       False)
            self.torrentlist.remove([i for i,x in enumerate(self.torrentlist) if x == torrent_id])
        except InvalidTorrentError:
            print "Clean torrents error: torrent does not exist!"


def checkdirectory(directory):
    contents = os.listdir(directory)
    i = 0
    while i < len(contents):
        if string.find(contents[i], ".torrent") > 0:
            return contents[i]
        i += 1
    return ""<commit_msg>Cleaned up code, still broken<commit_after>import os
import string

from deluge.ui.client import client
from deluge.error import InvalidTorrentError


class Monitor(object):
    def __init__(self):
        self.trackerlist = {"animebyt.es", "bakabt.me",
                            "bitgamer.su", "speed.cd", "what.cd"}
        self.torrentlist = []

    def addTorrent(self, torrent_id):
        self.torrentlist.append(torrent_id)

    def cleanTorrents(self):
        for torrent_id in self.torrentlist:
            status = client.core.get_torrent_status(torrent_id, ['tracker_host', 'ratio', 'active_time', 'progress'])
            status.addCallback(cleanUp, torrent_id)


def cleanUp(status, torrent_id):
    print status
    privatetracker = False
    for j in self.trackerlist:
        if status['tracker_host'] == j:
            privatetracker = True
            break

    if status['progress'] == 1:
        try:
            client.core.remove_torrent(torrent_id,
                                       False)
            self.torrentlist.remove([i for i,x in enumerate(self.torrentlist) if x == torrent_id])
        except InvalidTorrentError:
            print "Clean torrents error: torrent does not exist!"


def checkdirectory(directory):
    contents = os.listdir(directory)
    for i in contents:
        if string.find(i, ".torrent") > 0:
            return i
    return ""
{'fraction_non_alphanumeric': 0.10673608851285389, 'fraction_numerical': 0.004555808656036446, 'mean_word_length': 2.3160733549083066, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3649390', 'n_tokens_mistral': 946, 'n_tokens_neox': 899, 'n_words': 223}