From 08cbf7f445a2d23169b36c4bcd872376cbcc96b6 Mon Sep 17 00:00:00 2001 From: jblu Date: Wed, 20 Jul 2022 11:34:13 -0500 Subject: [PATCH] Added comments for the functions --- __pycache__/qlist.cpython-39.pyc | Bin 2373 -> 0 bytes __pycache__/qlogging.cpython-39.pyc | Bin 1461 -> 0 bytes __pycache__/qprocess.cpython-39.pyc | Bin 1734 -> 0 bytes qbit-maid.py | 11 +++++++++-- qlist.py | 10 +++++++++- qlogging.py | 7 ++++++- qprocess.py | 8 +++++++- 7 files changed, 31 insertions(+), 5 deletions(-) delete mode 100644 __pycache__/qlist.cpython-39.pyc delete mode 100644 __pycache__/qlogging.cpython-39.pyc delete mode 100644 __pycache__/qprocess.cpython-39.pyc diff --git a/__pycache__/qlist.cpython-39.pyc b/__pycache__/qlist.cpython-39.pyc deleted file mode 100644 index d61513eee89478498e4a9c376baf97cfee611ec7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2373 zcmcIl&2Jk;6rY)0f5dU(ByHNHRLOvZz=*^xLLfy|1++p!LT;rNMGaKe+B1&V+3c=o zCr-0+PU)TA5t4K4Uj&*fr`$Mj>WTMe*NKw|PO#R@ym=q<-uum)XK!w@(U3TP%cuxI;WHp*cDcZ zDDE*ew3-mdxo$a=g4GOA6>C*Qt2cCj9!g?%H9uiU)bE)mQ9ZYsJGXMJFXECu5%XUX z2JwP+c{~GiCDS@(5Dn?ij=>(a2UXaWMD4-@6`;0Ge%`v-yc<3RGjPjtegF4vJ#G6Y&jye)YWDJ{k3 z85WRnLvLTcqkL!954%y%OM0#0{hg9lUT04#L(;Y9nKc)YOu~;e?|DPXJ)Uc%jQ^OH zUZUX^H!iN}vL8=eZpi)ESF#r+I=%5!MOt>i_ave%o)$C9Gpy)zWy&zo5J5DQsvAUy z>HL(Wy&I>un^CwCUq7!|ubJ98ztxEjLT#49D7?y>%_BsRj1xz(VLC7cA=?MLrgZ43 z&<}UbVxDE|u;*)Obt{9mZgm1500nW5Y|9g(rM=z6EKe*h90K3my3V$z6}>o?p)jix zIfUA}Y&tEvkf3#)88?wZ*Oc-&-V(I}IKF${_#u%hY4oGe(>*V2D=+lI#`iuD>ZtK3 zhz`Uvu<>?f<4GtVD}N|Ao`MDF2aQf7WMk0w^~S#Ei^c$5ZN^8YY6}d^kbzw%`2r@w zinK_}v_jWtm3~59xRAGV>7y6`)3CH}C6mhh$c3&1GC zu<i$encN!CG!@`?PQ&pF(=~ zNf;dE4_)^p@A@jylh>8r`F48C{g9&$-riQ~Y;kUArCE0s{6P^_#R*|B1wds#sTVRd z3VtZ$D|H(sbkES?RYayYz>JI3aQtmd}Bhzyd4l zJAF)<P`GsMC2+6s zp(zaHYGT#=DBDXv1BJZoZ&I}hyJnrL_h5wuFBa+spLX^l@ak>qR&(lL>{2RwP!IMa UaS+IdwxM7U<@JhNDVGa>1Kg}z3IG5A diff --git a/__pycache__/qlogging.cpython-39.pyc b/__pycache__/qlogging.cpython-39.pyc deleted file mode 100644 index 89c46bb67a6f84180f7c9dd85b67e0818094443e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1461 zcmZ`(U27aS6dldijvc#oz%)*A!cZ8Kg*x*ZOb8{LrUaTzs2$qoWf-rtYuPi>MADjg z$y@U3Ur++cWByUmYyU+b(jIBoOQ>Ceq$^!r>CCz3PQAXq8lVlf|2+I94uZej;>#9d z@dLX49s><1c^AA4XhgvK<%9MY8bFh?|_E0|-tx*znfjR-<6nzMW819bfxhBv`+ zpbjt+N=`y`7gl&2VT|4FH1_L+Cg%wW#Ew6g;+%`Pd@h}zqXFLS4Q=x1$A>R|nia*J zT8|8GSzqrJcN%ue8c{D+Ez`Q5z%xsxX1sfEwpp}gLCfOzym+!#Jl!ky^P=k~HXHMX zxiFiKrD|(qGbTooaxt+zS{pWQjZOUJHhwaE{H))zy{TqZBPTY)Fn5KfvDXf3%|`<% z#vHM5b+tKCjvD2-`9y52Su_3=sIRg7``7Y?W=faGQs7)I4pl8`QU1(fsIzj=$SK`7 zQsFboXM#Oa{FLoJM+D9{B_Oi$)gd>#ZOv)<3eQb|`EGY+Qv_id;SufAPg1f!;}GLKW#k-omG}gN!#=Sqb;m0sPnhVZcFobzP4$sHWy*$~ zwCSMXOcs+o+QxwT^c@2lHVAOS=NlLK;3kbC9*e6acrniTVE#Z^G*k zJDE9QoreT6hD_q&Z0&$)lRupcVYag53VBEjHx28DY76mpO*28Og<`G*x4r~taOYPD z(ynp>qHbZl1TVv;uY`LrF5nqY=Uegz>dV`)w`$^MDM>~kE3pVfERxx~2Bx@Y`049EBf@)2|8Isf4QHXq4C8f1vFC&tF^*YPr% z8m*k(#5m1NFWyr0xn|dA(=% UTS=!4d*I8|DJJV>aTaCizfDhR-T(jq diff --git a/__pycache__/qprocess.cpython-39.pyc b/__pycache__/qprocess.cpython-39.pyc deleted file mode 100644 index a390813c4a975bac6703d535a0e486904c9d23a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1734 zcma)6&u`l`6t};>nkH#hM%N}~OrDSsL2A+=aj6g>twJ28FsVa8q$xPDlYWKDM`a~S$IObjvnBWfZRun_*3MJ$GYz>*_WUF%?gEIwxk{?L6G`d8R_ zhMu59^my_dGyDv*pn^`3+6OJ32Cxn*=qJRY^WXwwgwf~+(8U$Rl767R^{8-(TDwGz z64;BTG3@0k$l1=YY<-E&pNCHGk;x%?i68GjcM&YS|9mZmrT3S3^b6n$6=c>}@dfUK zt@_@hb4%|VGX%t5I*W$w-&n#d>Mg1urC7}v$$dB zzw^5}$E`*ht23~})5|#DUdFjKkMn=}9i5HN7=rt~)v#eYG&VA{r)?zYfKT2bW2#9i zh>&7$sHEW?!x_m^ZE7~wh8k`QOpZk+DN99f@*znz(I(9@vZ5wbFfw+^HYd8D4u_o8 zY#|k0c}(?j>-63ve{|9wq{exllt@=9!g$6_Dn+dsD+)sI_ut(2_h*wGcSxIOa!e?> zSKI%Xc)$m*akZJFjB(bIq8ZX22UkbDBL&k$X6%4W-oN6Sbd?+sbIi%L+-676wmjum zkC+72TD52^M$t~6s}}IGG;KLrY+y3GHl|7d9X4_)+Om;Kaba3MS)Ui5ffEW;2xhkz z{;oNTyFje5G2`u%o=qT=ZrZchT~a#W)xbuYXWeG5Lq*EqGF~Bd3m)X_Z|Yxbu5|s0 z6x1A3(NPdVt=C3E@00;%yxHISDrLE=W$3;G3A>JNP5KiOVnujNL%(fX$V5 z;#x}#!?%+MAV7JeDYOz3fE2#K@LYWBnCkA+Q9R1vlX|Vve!kBEZnj;aP``$=xsE zk@-hU^zxOhKCy#G)p(Z7CLG|SxA{@qv^rS|b!%@dXlTufS5+MBT4L(}nr*)ayYrli nxP;Zaux?aCf9pO$uUWD8o;*9bPX>~mWc*WKTQ2Y1?Ogm1?!?0? diff --git a/qbit-maid.py b/qbit-maid.py index cdd70a3..ab315f6 100644 --- a/qbit-maid.py +++ b/qbit-maid.py @@ -21,28 +21,32 @@ class Qbt: username=self.config["username"], password=self.config["password"], ) - # Create the logging object + # Create the logging and pushover objects self.tl = logging self.po = pushover + # Variables torlog uses from config.json self.use_pushover = self.config["use_pushover"] self.use_log = self.config["use_log"] self.po_key = self.config["po_key"] self.po_token = self.config["po_token"] - # Variables torlog uses from config.json self.logpath = self.config["logpath"] self.loglevel = self.config["loglevel"] + # Calling log and notify functions torlog(self) tornotify(self) self.t = time + # Pulling domain names to treat carefully f = open('./tracker-whitelist.json') self.tracker_whitelist = load(f) self.tracker_protected_list = [] self.tracker_nonprotected_list = [] + # Setting values of the tags self.tracker_protected_tag = 'ipt' self.tracker_non_protected_tag = 'public' self.torrent_hash_delete_list = [] if self.use_log: self.tl.debug(self.tracker_whitelist) + #logging in try: self.tl.info('Connecting to host.') self.qbt_client.auth_log_in() @@ -51,7 +55,9 @@ class Qbt: self.tl.exception(e) self.poc.send_message(e, title="qbit-maid API ERROR") self.torrentlist = {} + # Pulling all torrent data self.torrentlist = self.qbt_client.torrents_info() + #Main process block if self.use_log: listqbitapiinfo(self) listfirsttor(self) @@ -65,5 +71,6 @@ class Qbt: tornotifysummary(self) tordelete(self) +# Run if __name__== "__main__": Qbt() \ No newline at end of file diff --git a/qlist.py b/qlist.py index ae9f5b2..bade55b 100644 --- a/qlist.py +++ b/qlist.py @@ -1,6 +1,10 @@ #The second file shall contain functions to build out a list of torrents. def buildtorlist(self): - """builds multiple lists of torrents to be sorted.""" + """Builds multiple lists of torrents to be sorted. Also adds tags to the torents. + There are more effecient ways of doing things but I did this rather quickly. + V2 will certainly be more performant. The reason two lists were used was so that torrents + that are in public trackers woudln't be around as long as torrents from a private tracker. + """ self.protected_count = 0 self.nonprotected_count = 0 while self.torrentlist: @@ -37,6 +41,9 @@ def buildtorlist(self): self.tracker_nonprotected_list.append(torrent) def writetor(self, filepath='./torrentinfo.txt'): + """Write all torrent data to a file. + Useful for development of new features. + """ with open(filepath, 'w') as fp: fp.write(str(self.torrentlist)) @@ -54,5 +61,6 @@ def listqbitapiinfo(self): self.tl.debug(f'qBittorrent Web API: {self.qbt_client.app.web_api_version}') def torrentcount(self): + """write torrent counts to log file""" self.tl.debug(f'torrents that are protected {self.protected_count}') self.tl.debug(f"torrents that aren't protected {self.nonprotected_count}") \ No newline at end of file diff --git a/qlogging.py b/qlogging.py index ff3c2f1..4aa5f29 100644 --- a/qlogging.py +++ b/qlogging.py @@ -1,6 +1,7 @@ #The third file shall contain logging and email communication. def torlog(self): + """Setting up the log file, if self.use_log is set to true and self.loglevel is DEBUG OR INFO""" if self.use_log: if self.loglevel == 'DEBUG': self.tl.basicConfig(filename=self.logpath, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.DEBUG) @@ -8,18 +9,22 @@ def torlog(self): self.tl.basicConfig(filename=self.logpath, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.INFO) def tornotify(self): + """Seting up to use pushover, if self.use_pushover is set to true and + if valid self.po_key and self.po_token is provided in the config file""" if self.use_pushover: self.poc = self.po.Client(self.po_key, api_token=self.po_token) def tornotifytest(self): + """Used to make sure tornotify is working and messages are getting to the client""" self.poc.send_message("Test Message", title="qbit-maid") def tornotifysummary(self): + """Main notification method when the app is used in an automated fashion""" self.poc.send_message(f' Protected torrents: {len(self.tracker_protected_list)}\n\ Non-protected torrents: {len(self.tracker_nonprotected_list)}\n\ Total torrents set for deletion: {len(self.torrent_hash_delete_list)}', title="qbit-maid summary") - def getunixtimestamp(self): + """Used for debuging and development related to unixtimestamps, not used in main script but useful""" self.uts = self.t.time() self.tl.info(self.uts) \ No newline at end of file diff --git a/qprocess.py b/qprocess.py index 0049ef3..c638362 100644 --- a/qprocess.py +++ b/qprocess.py @@ -1,5 +1,8 @@ #The fourth file shall be logic to process torrents. def torprocessor(self): + """Main logic to sort through both self.tracker_nonprotected_list and self.tracker_protected_list + If torrent meets criteria for deletion, its infohash_v1 will be appended to self.torrent_hash_delete_list + """ for canidate in self.tracker_nonprotected_list: if 'ipt' in canidate['tags']: if self.use_log: @@ -37,12 +40,15 @@ def torprocessor(self): pass def printprocessor(self): + """Print summary of torrents""" self.tl.info(f'Protected torrents: {len(self.tracker_protected_list)}') self.tl.info(f'Non-protected torrents: {len(self.tracker_nonprotected_list)}') self.tl.info(f'Total torrents set for deletion: {len(self.torrent_hash_delete_list)}') def tordelete(self): + """Remove torrents, will also delete files, this keeps the filesystem clean. + Only pass self.torrent_hash_delete_list if you would like to keep the files.""" if self.use_log: self.tl.debug('Hash list submitted for deletion:') - self.tl.debug(self.torrent_hash_delete_list) + self.tl.debug(self.torrent_hash_delete_list) self.qbt_client.torrents_delete(True, self.torrent_hash_delete_list) \ No newline at end of file