diff --git a/.gitignore b/.gitignore index af0d4f7..da47f49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.log *.json +*.csv # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/qbit-maid.py b/qbit-maid.py index 85ad5b5..f6c90c9 100644 --- a/qbit-maid.py +++ b/qbit-maid.py @@ -9,6 +9,7 @@ import time import datetime import logging from collections import Counter +import csv class Qbt: def __init__(self): @@ -30,6 +31,7 @@ class Qbt: self.tl = logging self.po = pushover self.ct = Counter + self.cv = csv # Variables torlog uses from config.json self.use_pushover = self.config["use_pushover"] self.use_log = self.config["use_log"] @@ -63,7 +65,6 @@ class Qbt: except qbittorrentapi.APIError as e: self.tl.exception(e) self.po.send_message(e, title="qbit-maid API ERROR") - # self.torrentlist = {} # Pulling all torrent data self.torrentlist = self.qbt_client.torrents_info() #Main process block diff --git a/qprocess.py b/qprocess.py index c148f36..95b08bc 100644 --- a/qprocess.py +++ b/qprocess.py @@ -32,7 +32,7 @@ def torprocessor(self): if self.use_log: self.tl.info(f'Submitted ["{canidate["name"][0:20]}..."] for deletion.') else: - dragnet(canidate['state'],canidate['ratio'],canidate["tags"],canidate['added_on'],self.age,self.t.time(),canidate['infohash_v1'],canidate["name"][0:20]) + dragnet(self,canidate['state'],canidate['ratio'],canidate["tags"],canidate['added_on'],self.age,self.t.time(),canidate['infohash_v1'],canidate["name"][0:20]) self.tl.info(f'["{canidate["name"][0:20]}..."] is orphaned.') self.up_tor_counter += 1 continue @@ -69,5 +69,11 @@ def isnonprotectedtor(setnonprotectedtag, tortags): if setnonprotectedtag in tortags: return True -def dragnet(state,ratio,tags,added,age,time,thash,tname): - pass \ No newline at end of file +def dragnet(self,state,ratio,tags,added,age,time,thash,tname): + header = ['state','ratio','tags','added','age','time','thash','tname'] + row = [state,ratio,tags,added,age,time,thash,tname] + with open('./orphanedtorrents.csv', 'w', encoding='UTF8', newline='') as f: + writer = self.cv.writer(f) + if f.tell() == 0: + writer.writerow(header) + writer.writerow(row) \ No newline at end of file diff --git a/test_qbitmaid.py b/test_qbitmaid.py index 1f993f2..230f397 100644 --- a/test_qbitmaid.py +++ b/test_qbitmaid.py @@ -85,8 +85,6 @@ class TestQbitmaid(unittest.TestCase): def test_isnonprotectedtor(self): pass - pass - # def test__sanity(self): # pass