Moved to apscheduler

This commit is contained in:
Profitroll 2023-01-09 15:36:56 +01:00
parent cd5b73e7ff
commit cddf1e211a
3 changed files with 31 additions and 25 deletions

View File

@ -1,12 +1,13 @@
from datetime import datetime
from os import sep, remove, getpid, listdir
from random import choice
from shutil import move
from sys import argv, exit
from threading import Thread
from sys import exit
from time import time
from traceback import format_exc
from pathlib import Path
from argparse import ArgumentParser
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from modules.logging import logWrite
from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale
@ -86,6 +87,8 @@ except ModuleNotFoundError:
pid = getpid()
app = Client("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
if configGet("post", "mode"):
scheduler = AsyncIOScheduler()
# Work in progress
# def check_forwards(app):
@ -413,23 +416,25 @@ def callback_query_unblock(app, clb): # type: ignore
if configGet("post", "mode"):
for entry in configGet("time", "posting"):
schedule.every().day.at(entry).do(send_content)
dt_obj = datetime.strptime(entry, "%H:%M")
scheduler.add_job(send_content, "cron", hour=dt_obj.hour, minute=dt_obj.minute)
# schedule.every().day.at(entry).do(send_content)
def background_task():
try:
while True:
try:
schedule.run_pending()
time.sleep(1)
except:
pass
except Exception as exp:
logWrite(locale("exception_occured", "console", locale=configGet("locale")).format(exp))
except KeyboardInterrupt:
logWrite(locale("keyboard_interrupt", "console", locale=configGet("locale")))
if configGet("shutdown", "reports"):
app.send_message(configGet("admin"), locale("shutdown", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
killProc(pid)
# def background_task():
# try:
# while True:
# try:
# schedule.run_pending()
# time.sleep(1)
# except:
# pass
# except Exception as exp:
# logWrite(locale("exception_occured", "console", locale=configGet("locale")).format(exp))
# except KeyboardInterrupt:
# logWrite(locale("keyboard_interrupt", "console", locale=configGet("locale")))
# if configGet("shutdown", "reports"):
# app.send_message(configGet("admin"), locale("shutdown", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
# killProc(pid)
if __name__ == "__main__":
@ -439,9 +444,9 @@ if __name__ == "__main__":
if configGet("startup", "reports"):
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
if configGet("post", "mode"):
t = Thread(target=background_task)
t.start()
# if configGet("post", "mode"):
# t = Thread(target=background_task)
# t.start()
if configGet("submit", "mode"):
# Registering user commands

View File

@ -1 +1,2 @@
ujson
ujson~=5.7.0
tgcrypto~=1.2.5

View File

@ -1,3 +1,3 @@
schedule
pyrogram>=2.0.0
psutil
apscheduler~=3.9.1.post1
pyrogram~=2.0.96
psutil~=5.9.4