2022-09-03 15:02:40 -05:00
|
|
|
def tor_log(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""Setting up the log file, if self.use_log is set to true and self.loglevel is DEBUG OR INFO"""
|
|
|
|
if self.use_log:
|
2022-11-01 16:12:49 -05:00
|
|
|
if self.log_level.lower() == 'debug':
|
2022-09-03 18:55:51 -05:00
|
|
|
self.tl.basicConfig(filename=self.log_path, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.DEBUG)
|
2022-11-01 16:12:49 -05:00
|
|
|
elif self.log_level.lower() == 'info':
|
2022-09-03 18:55:51 -05:00
|
|
|
self.tl.basicConfig(filename=self.log_path, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.INFO)
|
2022-11-01 16:12:49 -05:00
|
|
|
elif self.log_level.lower() == 'warn':
|
|
|
|
self.tl.basicConfig(filename=self.log_path, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.WARN)
|
|
|
|
elif self.log_level.lower() == 'error':
|
|
|
|
self.tl.basicConfig(filename=self.log_path, format='%(asctime)s:%(levelname)s:%(message)s', encoding='utf-8', datefmt='%m/%d/%Y %I:%M:%S %p',level=self.tl.ERROR)
|
2022-07-29 16:02:19 -05:00
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def tor_notify(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""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:
|
2022-11-01 15:33:22 -05:00
|
|
|
self.poc = self.po.Pushover(self.po_token)
|
2022-07-29 16:02:19 -05:00
|
|
|
|
2023-05-16 22:05:12 -05:00
|
|
|
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)
|
|
|
|
|
2022-07-29 16:02:19 -05:00
|
|
|
def tornotifytest(self):
|
|
|
|
"""Used to make sure tornotify is working and messages are getting to the client"""
|
2022-11-01 15:33:22 -05:00
|
|
|
self.poc.message(self.po_key, "Test Message", title="qbit-maid")
|
2022-07-29 16:02:19 -05:00
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def process_counts(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
self.c = self.ct()
|
|
|
|
for item in self.tracker_list:
|
|
|
|
self.c[item["tags"]] += 1
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def print_processor(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""Print summary of torrents"""
|
|
|
|
self.tl.info(f'Total: {self.total_torrents}')
|
|
|
|
self.tl.info(f'Premature: {self.preme_tor_counter}')
|
|
|
|
self.tl.info(f'Ignored: {self.ignored_counter}')
|
|
|
|
self.tl.info(f'Protected: {self.c[self.tracker_protected_tag]}')
|
|
|
|
self.tl.info(f'Non-protected: {self.c[self.tracker_non_protected_tag]}')
|
|
|
|
self.tl.info(f'Orphaned: {self.up_tor_counter}')
|
|
|
|
self.tl.info(f'Marked for deletion: {len(self.torrent_hash_delete_list)}')
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def tor_notify_summary(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""Main notification method when the app is used in an automated fashion"""
|
2022-11-01 15:33:22 -05:00
|
|
|
self.poc.message(self.po_key, f" Total: {self.total_torrents}\n\
|
2022-07-29 16:02:19 -05:00
|
|
|
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\
|
2022-08-01 13:01:00 -05:00
|
|
|
Marked for deletion: {len(self.torrent_hash_delete_list)}\n\
|
|
|
|
{self.extm}", title="--- qbit-maid summary ---")
|
2022-07-29 16:02:19 -05:00
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def list_first_tor(self, index=0):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""Only lists the first torrent"""
|
|
|
|
self.tl.debug('First torrent in the list:')
|
2022-09-03 18:55:51 -05:00
|
|
|
torrent = self.torrent_list[index]
|
2022-07-29 16:02:19 -05:00
|
|
|
for k,v in torrent.items():
|
|
|
|
self.tl.debug(f'{k}: {v}')
|
|
|
|
self.tl.debug('\n')
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def list_qbit_api_info(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""Writes torrent info to log file"""
|
|
|
|
self.tl.debug(f'qBittorrent: {self.qbt_client.app.version}')
|
|
|
|
self.tl.debug(f'qBittorrent Web API: {self.qbt_client.app.web_api_version}')
|
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def torrent_count(self):
|
2022-07-29 16:02:19 -05:00
|
|
|
"""write torrent counts to log file"""
|
2022-10-01 13:10:42 -05:00
|
|
|
self.tl.debug(f'*** Torrents with tag["{self.tracker_protected_tag}"] {self.c[self.tracker_protected_tag]} ***')
|
|
|
|
self.tl.debug(f'*** Torrents with tag["{self.tracker_non_protected_tag}"] {self.c[self.tracker_non_protected_tag]} ***')
|
2022-08-01 13:01:00 -05:00
|
|
|
|
2022-09-03 15:02:40 -05:00
|
|
|
def get_script_runtime(self):
|
2022-08-01 13:01:00 -05:00
|
|
|
elapsed_time = self.et - self.st
|
|
|
|
if self.use_log:
|
|
|
|
self.tl.info(f'Execution time: [{elapsed_time}]')
|
|
|
|
if self.use_pushover:
|
2023-05-16 22:05:12 -05:00
|
|
|
self.extm = f"Execution time: [{elapsed_time}]"
|
|
|
|
if self.use_apprise:
|
2023-06-05 23:51:49 -05:00
|
|
|
self.extm = f"Execution time: [{elapsed_time}]"
|
|
|
|
|
|
|
|
def send_ping(self, req_obj, healthcheck_url):
|
|
|
|
try:
|
|
|
|
req_obj.get(healthcheck_url, timeout=10)
|
|
|
|
except req_obj.RequestException as e:
|
|
|
|
self.tl.info(f"Ping failed: {e}")
|