crane/clogging.py

50 lines
2.4 KiB
Python
Raw Permalink Normal View History

2022-10-17 17:18:17 -05:00
def cont_log(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:
2022-11-01 16:10:22 -05:00
if self.log_level.lower() == 'debug':
2022-10-17 17:18:17 -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:10:22 -05:00
elif self.log_level.lower() == 'info':
2022-10-17 17:18:17 -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:10:22 -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-10-17 17:18:17 -05:00
def cont_notify(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:
2022-10-30 23:27:08 -05:00
self.poc = self.po.Pushover(self.po_token)
2022-10-17 17:18:17 -05:00
2023-06-05 22:30:53 -05:00
def cont_notify_summary(self, app_obj, req_obj):
2022-10-17 17:18:17 -05:00
"""Main notification method when the app is used in an automated fashion"""
2023-06-05 22:30:53 -05:00
title = "--- crane summary ---"
body = f'{self.extm}'
2022-11-01 15:49:36 -05:00
if self.use_pushover:
2023-06-05 22:30:53 -05:00
#TODO figure out why the flip it thinks its getting 4 pos args
self.poc.message(self.po_key, message=body, title=title)
if self.use_apprise:
app_obj(req_obj, self.apprise_host, self.apprise_port, self.apprise_aurls, title, body)
2022-10-17 17:18:17 -05:00
def list_first_cont(self, index=0):
"""Only lists the first torrent"""
self.tl.debug('First torrent in the list:')
torrent = self.torrent_list[index]
for k,v in torrent.items():
self.tl.debug(f'{k}: {v}')
self.tl.debug('\n')
def get_script_runtime(self):
elapsed_time = self.et - self.st
if self.use_log:
self.tl.info(f'Execution time: [{elapsed_time}]')
if self.use_pushover:
2023-06-05 22:30:53 -05:00
self.extm = f"Execution time: [{elapsed_time}]"
if self.use_apprise:
2023-06-05 23:10:33 -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}")