added apprise client
This commit is contained in:
		
							
								
								
									
										40
									
								
								AppriseClient.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								AppriseClient.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| import requests as r | ||||
| from tomllib import load | ||||
| import os | ||||
|  | ||||
| def apprise_notify(req_obj, host, port, aurls, title, body): | ||||
|     payload = {'urls': aurls,'title': title,'body': body,} | ||||
|     url = f'http://{host}:{port}/notify/' | ||||
|     apprise_response = req_obj.post(url, json = payload ,verify=False) | ||||
|     return apprise_response | ||||
|  | ||||
| class AppriseClient: | ||||
|     def __init__(self): | ||||
|         self.config = '' | ||||
|         try: | ||||
|             if os.environ["DOCKER"]: | ||||
|                 self.host = os.environ["host"] | ||||
|                 self.port = os.environ["port"] | ||||
|                 self.aurls = os.environ["aurls"] | ||||
|                 self.title = os.environ["title"] | ||||
|                 self.body = os.environ["body"] | ||||
|             if os.environ["toml_path"]: | ||||
|                 config_file_path=os.environ["toml_path"] | ||||
|                 with open(config_file_path, 'rb') as c: | ||||
|                     self.config = load(c) | ||||
|         except: | ||||
|             KeyError | ||||
|         if os.path.exists('./config.toml'): | ||||
|             config_file_path = './config.toml' | ||||
|             with open(config_file_path, 'rb') as c: | ||||
|                 self.config = load(c) | ||||
|         if self.config: | ||||
|             self.host = self.config["apprise"]["host"] | ||||
|             self.port = self.config["apprise"]["port"] | ||||
|             self.aurls = self.config["apprise"]["aurls"] | ||||
|             self.title = self.config["apprise"]["title"] | ||||
|             self.body = self.config["apprise"]["body"] | ||||
|         self.apprise_response = apprise_notify(r,self.host,self.port,self.aurls,self.title,self.body)   | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     AppriseClient() | ||||
| @@ -23,6 +23,11 @@ use_pushover = false | ||||
| po_key = "" | ||||
| po_token = "" | ||||
|  | ||||
| [apprise] | ||||
| host = "192.168.x.x" | ||||
| port = 8088 | ||||
| aurls = 'mailto://user:pass@gmail.com' | ||||
|  | ||||
| [dragnet] | ||||
| enable_dragnet = true | ||||
| dragnet_outfile = "./orphaned.csv" | ||||
|   | ||||
							
								
								
									
										10
									
								
								qbit-maid.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								qbit-maid.py
									
									
									
									
									
								
							| @@ -4,11 +4,13 @@ from tomllib import load | ||||
| from qlist import * | ||||
| from qlogging import * | ||||
| from qprocess import * | ||||
| from AppriseClient import apprise_notify | ||||
| import time | ||||
| import datetime | ||||
| import logging | ||||
| from collections import Counter | ||||
| import csv | ||||
| import requests as r | ||||
|  | ||||
| class Qbt: | ||||
|     def __init__(self): | ||||
| @@ -52,6 +54,12 @@ class Qbt: | ||||
|         self.po_key = self.config["pushover"]["po_key"] | ||||
|         self.po_token = self.config["pushover"]["po_token"] | ||||
|  | ||||
|         #apprise | ||||
|         self.use_apprise = self.config["apprise"]["use_apprise"] | ||||
|         self.apprise_host = self.config["apprise"]["host"] | ||||
|         self.apprise_port = self.config["apprise"]["port"] | ||||
|         self.apprise_aurls = self.config["apprise"]["aurls"] | ||||
|  | ||||
|         #dragnet | ||||
|         self.enable_dragnet = self.config["dragnet"]["enable_dragnet"] | ||||
|         self.dragnet_outfile = self.config["dragnet"]["dragnet_outfile"] | ||||
| @@ -104,6 +112,8 @@ class Qbt: | ||||
|         get_script_runtime(self) | ||||
|         if self.use_pushover: | ||||
|             tor_notify_summary(self) | ||||
|         if self.use_apprise: | ||||
|             tor_notify_apprise(self, r, apprise_notify) | ||||
| # Run | ||||
| if  __name__== "__main__": | ||||
|     Qbt() | ||||
							
								
								
									
										15
									
								
								qlogging.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								qlogging.py
									
									
									
									
									
								
							| @@ -16,6 +16,19 @@ def tor_notify(self): | ||||
|     if self.use_pushover: | ||||
|         self.poc = self.po.Pushover(self.po_token) | ||||
|  | ||||
| def tor_notify_apprise(self, req_obj, app_obj): | ||||
|     """Use apprise""" | ||||
|     body = f"   Total: {self.total_torrents}\n\ | ||||
|     Premature: {self.preme_tor_counter}\n\ | ||||
|     Ignored: {self.ignored_counter}\n\ | ||||
|     Protected: {self.c[self.tracker_protected_tag]}\n\ | ||||
|     Non-protected: {self.c[self.tracker_non_protected_tag]}\n\ | ||||
|     Orphaned: {self.up_tor_counter}\n\ | ||||
|     Marked for deletion: {len(self.torrent_hash_delete_list)}\n\ | ||||
|     {self.extm}" | ||||
|     title = "--- qbit-maid summary ---" | ||||
|     app_obj(req_obj, self.apprise_host, self.apprise_port, self.apprise_aurls, title, body) | ||||
|  | ||||
| def tornotifytest(self): | ||||
|     """Used to make sure tornotify is working and messages are getting to the client""" | ||||
|     self.poc.message(self.po_key, "Test Message", title="qbit-maid") | ||||
| @@ -69,4 +82,6 @@ def get_script_runtime(self): | ||||
|     if self.use_log: | ||||
|         self.tl.info(f'Execution time: [{elapsed_time}]') | ||||
|     if self.use_pushover: | ||||
|         self.extm = f"Execution time: [{elapsed_time}]" | ||||
|     if self.use_apprise: | ||||
|         self.extm = f"Execution time: [{elapsed_time}]" | ||||
		Reference in New Issue
	
	Block a user