fix: logging

This commit is contained in:
2025-04-13 21:15:50 +03:00
parent 9c80afa351
commit 166ad0ba2f
8 changed files with 297 additions and 86 deletions
+7 -3
View File
@@ -1,14 +1,18 @@
import logging
import os
import psycopg2
from datetime import datetime
from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetHistoryRequest
LOG_FILE = os.getenv('LOG_FILE', '/app/tg_nodes.log')
if os.path.exists(LOG_FILE) and os.path.isdir(LOG_FILE):
raise RuntimeError(f"Path {LOG_FILE} is a directory! Expected file.")
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('tg_nodes.log'),
logging.FileHandler(LOG_FILE),
logging.StreamHandler()
]
)
+34 -21
View File
@@ -1,34 +1,47 @@
import asyncio
import os
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.schedulers.background import BackgroundScheduler
from pytz import timezone
from tg_crawler import TelegramChannelMonitor
from dotenv import load_dotenv
import logging
load_dotenv()
TelegramChannelMonitor.set_db_config({
'host': os.getenv("HOST"),
'port': os.getenv("PORT"),
'database': os.getenv("DBNAME"),
'user': os.getenv("USER"),
'password': os.getenv("PASSWORD")
})
monitor = TelegramChannelMonitor(
session_name='session_trueosint',
api_id=os.getenv("TELETHON_API_ID"),
api_hash=os.getenv("TELETHON_API_HASH"),
channel_username='trueosint',
source_name='trueosint'
)
def main():
scheduler = AsyncIOScheduler()
scheduler.add_job(monitor.fetch_last_post, "cron", hour=9, minute=0, timezone=timezone("Europe/Moscow"))
scheduler.start()
TelegramChannelMonitor.set_db_config({
'host': os.getenv("HOST"),
'port': os.getenv("PORT"),
'database': os.getenv("DBNAME"),
'user': os.getenv("USER"),
'password': os.getenv("PASSWORD")
})
asyncio.get_event_loop().run_forever()
monitor = TelegramChannelMonitor(
session_name='session_trueosint',
api_id=os.getenv("TELETHON_API_ID"),
api_hash=os.getenv("TELETHON_API_HASH"),
channel_username='trueosint',
source_name='trueosint'
)
scheduler = BackgroundScheduler()
scheduler.add_job(
monitor.fetch_last_post,
'cron',
hour=9,
minute=0,
timezone=timezone("Europe/Moscow")
)
try:
scheduler.start()
logging.info("Scheduler started successfully")
while True:
pass
except (KeyboardInterrupt, SystemExit):
scheduler.shutdown()
logging.info("Scheduler shut down successfully")
if __name__ == '__main__':
main()
+35 -21
View File
@@ -1,34 +1,48 @@
import asyncio
import os
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.schedulers.background import BackgroundScheduler
from pytz import timezone
from tg_crawler import TelegramChannelMonitor
from dotenv import load_dotenv
import logging
load_dotenv()
TelegramChannelMonitor.set_db_config({
'host': os.getenv("HOST"),
'port': os.getenv("PORT"),
'database': os.getenv("DBNAME"),
'user': os.getenv("USER"),
'password': os.getenv("PASSWORD")
})
monitor = TelegramChannelMonitor(
session_name='session_dataleak',
api_id=os.getenv("TELETHON_API_ID"),
api_hash=os.getenv("TELETHON_API_HASH"),
channel_username='dataleak',
source_name='dataleak'
)
def main():
scheduler = AsyncIOScheduler()
scheduler.add_job(monitor.fetch_last_post, "cron", hour=9, minute=0, timezone=timezone("Europe/Moscow"))
scheduler.start()
TelegramChannelMonitor.set_db_config({
'host': os.getenv("HOST"),
'port': os.getenv("PORT"),
'database': os.getenv("DBNAME"),
'user': os.getenv("USER"),
'password': os.getenv("PASSWORD")
})
asyncio.get_event_loop().run_forever()
monitor = TelegramChannelMonitor(
session_name='session_trueosint',
api_id=os.getenv("TELETHON_API_ID"),
api_hash=os.getenv("TELETHON_API_HASH"),
channel_username='dataleak',
source_name='dataleak'
)
scheduler = BackgroundScheduler()
scheduler.add_job(
monitor.fetch_last_post,
'cron',
hour=9,
minute=0,
timezone=timezone("Europe/Moscow")
)
try:
scheduler.start()
logging.info("Scheduler started successfully")
while True:
pass
except (KeyboardInterrupt, SystemExit):
scheduler.shutdown()
logging.info("Scheduler shut down successfully")
if __name__ == '__main__':
main()