#!/bin/python import transmissionrpc import csv # Connect to Transmission server with authentication tc = transmissionrpc.Client('192.168.1.2', port=9091, user='synbt', password='synbt') # Retrieve list of torrents with error messages torrents = tc.get_torrents(arguments=['id', 'name', 'status', 'progress', 'magnetLink', 'errorString']) torrents_with_errors = [t for t in torrents if t.errorString != ''] # Iterate over each torrent with errors for torrent in torrents_with_errors: # Output the torrent information print(f"Name: {torrent.name}\nError: {torrent.errorString}") # Ask for confirmation to delete and re-add the torrent confirmation = input("Delete and re-add this torrent? (y/n): ").strip().lower() if confirmation == 'y': # Delete the torrent and re-add it with the magnet link tc.remove_torrent(torrent.id, delete_data=True) tc.add_torrent(torrent.magnetLink) print(f"{torrent.name} has been deleted and re-added.") else: print(f"{torrent.name} will not be deleted and re-added.") # Output the torrent information to a CSV file with open('torrent_info.csv', 'w', newline='') as csvfile: fieldnames = ['id', 'name', 'magnet', 'error'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for torrent in torrents_with_errors: writer.writerow({'id': torrent.id, 'name': torrent.name, 'magnet': torrent.magnetLink, 'error': torrent.errorString})