48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import asyncio
|
|
import os
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from pytz import timezone
|
|
from tg_crawler import TelegramChannelMonitor
|
|
from dotenv import load_dotenv
|
|
import logging
|
|
|
|
load_dotenv()
|
|
|
|
def main():
|
|
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'
|
|
)
|
|
|
|
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()
|