def test_add_list_info_and_remove(self): count_before = len(utils.torrent_list()) self.assertEqual(utils.torrent_add(TORRENT_MAGNET), TRANSMISSION_MSG_SUCCESS) self.assertEqual(utils.torrent_add(TORRENT_MAGNET), 'Error: duplicate torrent') torrents = utils.torrent_list() count_after = len(torrents) added_torrent = torrents[-1] self.assertTrue(utils.torrent_info(added_torrent.id)) self.assertEqual(count_after, count_before + 1) self.assertEqual(utils.torrent_remove(added_torrent.id), TRANSMISSION_MSG_SUCCESS)
def check_if_downloaded(self): torrents = utils.torrent_list() torrents_by_status = defaultdict(set) for t in torrents: if t.done == "100%": torrents_by_status["done"].add(t) else: torrents_by_status["downloading"].add(t) recently_completed = (self.downloading_torrents - torrents_by_status["downloading"]) & torrents_by_status["done"] self.downloading_torrents = torrents_by_status["downloading"] for t in recently_completed: self.send_message(self._user_id, "Torrent '_%s_' has been downloaded " % t.name + EMOJI_THUMBS_UP, parse_mode="Markdown") threading.Timer(INTERVAL, self.check_if_downloaded).start()
def torrent_list_by_status(message): log.info("Handling command list torrents - %s" % message.text) torrents = utils.torrent_list() log.info("Torrents: %s", torrents) torrents_by_type = defaultdict(list) for torrent in torrents: torrents_by_type[torrent.status].append(torrent) response = "" for key in torrents_by_type.keys(): response += "*%s*\n" % TorrentStatus.conversion_to_string[key] for t in torrents_by_type[key]: response += t.format_telegram() + "\n" bot.reply_to(message, response, parse_mode="Markdown")
def torrent_list_by_status(message): log.info("Handling command list torrents - %s" % message.text) torrents = utils.torrent_list() log.info("Torrents: %s", torrents) torrents_by_type = defaultdict(list) for torrent in torrents: torrents_by_type[torrent.status].append(torrent) response = "" for key in torrents_by_type.keys(): response += "*%s*\n" % TorrentStatus.conversion_to_string[key] for t in torrents_by_type[key]: response += t.format_telegram() + "\n" if (len(response) == 0): response = "No active torrents" bot.reply_to(message, response, parse_mode="Markdown")
def check_if_downloaded(self): torrents = utils.torrent_list() torrents_by_status = defaultdict(set) for t in torrents: if t.done == "100%": torrents_by_status["done"].add(t) else: torrents_by_status["downloading"].add(t) recently_completed = ( self.downloading_torrents - torrents_by_status["downloading"]) & torrents_by_status["done"] self.downloading_torrents = torrents_by_status["downloading"] for t in recently_completed: for id_item in self._user_id: self.send_message( id_item, "Torrent '_%s_' has been downloaded " % t.name + EMOJI_THUMBS_UP, parse_mode="Markdown") #self.send_message(self._user_id, "Torrent '_%s_' has been downloaded " % t.name + EMOJI_THUMBS_UP, parse_mode="Markdown") threading.Timer(INTERVAL, self.check_if_downloaded).start()
def test_torrent_list(self): torrents = utils.torrent_list() self.assertIsInstance(torrents[0], Torrent)