refactor wip
This commit is contained in:
@ -33,7 +33,7 @@ class TelegramUtils:
|
||||
await self.initialize()
|
||||
|
||||
try:
|
||||
# await self.bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=f"[{BOT_NAME}] {message}", parse_mode=ParseMode.HTML)
|
||||
await self.bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=f"[{BOT_NAME}] {message}", parse_mode=ParseMode.HTML)
|
||||
logging.info(f"Telegram message sent: {message}")
|
||||
except Exception as e:
|
||||
logging.error(f"Error sending Telegram message: {str(e)}")
|
||||
@ -42,10 +42,7 @@ class TelegramUtils:
|
||||
if self.conn_pool:
|
||||
await self.conn_pool.close()
|
||||
|
||||
|
||||
class Log:
|
||||
# Set up success logger for accounting CSV
|
||||
class CSVFormatter(logging.Formatter):
|
||||
class CSVFormatter(logging.Formatter):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.output = None
|
||||
@ -66,7 +63,9 @@ class Log:
|
||||
record.wallet_address
|
||||
])
|
||||
return ''
|
||||
|
||||
class Log:
|
||||
# Set up success logger for accounting CSV
|
||||
|
||||
def __init__(self):
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@ -85,7 +84,7 @@ class Log:
|
||||
error_logger.addHandler(error_file_handler)
|
||||
success_log_file = os.path.join(log_dir, 'successful_swaps.csv')
|
||||
success_file_handler = RotatingFileHandler(success_log_file, maxBytes=10*1024*1024, backupCount=5)
|
||||
success_file_handler.setFormatter(self.CSVFormatter())
|
||||
success_file_handler.setFormatter(CSVFormatter())
|
||||
success_logger_accounting_csv = logging.getLogger('success_logger_accounting_csv')
|
||||
success_logger_accounting_csv.setLevel(logging.INFO)
|
||||
success_logger_accounting_csv.addHandler(success_file_handler)
|
||||
@ -104,9 +103,39 @@ class Log:
|
||||
})
|
||||
|
||||
|
||||
def safe_get_property(info, property_name, default='Unknown'):
|
||||
if not isinstance(info, dict):
|
||||
return str(default)
|
||||
value = info.get(property_name, default)
|
||||
return str(value) if value is not None else str(default)
|
||||
|
||||
|
||||
|
||||
# Create a global instance of TelegramUtils
|
||||
telegram_utils = TelegramUtils()
|
||||
log = Log()
|
||||
# You can add more Telegram-related methods to the TelegramUtils class if needed
|
||||
# You can add more Telegram-related methods to the TelegramUtils class if needed
|
||||
|
||||
|
||||
|
||||
pk = os.getenv("PK")
|
||||
async def get_pk():
|
||||
global pk
|
||||
if not pk:
|
||||
try:
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
with open(os.path.join(script_dir, 'secret.pk'), 'r') as f:
|
||||
pk = f.read().strip()
|
||||
if pk:
|
||||
logging.info("Private key loaded successfully from file.")
|
||||
else:
|
||||
logging.warning("Private key file is empty.")
|
||||
except FileNotFoundError:
|
||||
logging.warning("Private key file not found.")
|
||||
except Exception as e:
|
||||
logging.error(f"Error reading private key file: {str(e)}")
|
||||
if not pk:
|
||||
logging.error("Private key not found in environment variables. Will not be able to sign transactions.")
|
||||
# send TG warning message
|
||||
await telegram_utils.send_telegram_message("<b>Warning:</b> Private key not found in environment variables. Will not be able to sign transactions.")
|
||||
return pk
|
Reference in New Issue
Block a user