Moved to apscheduler
This commit is contained in:
parent
cd5b73e7ff
commit
cddf1e211a
47
poster.py
47
poster.py
@ -1,12 +1,13 @@
|
|||||||
|
from datetime import datetime
|
||||||
from os import sep, remove, getpid, listdir
|
from os import sep, remove, getpid, listdir
|
||||||
from random import choice
|
from random import choice
|
||||||
from shutil import move
|
from shutil import move
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
from threading import Thread
|
|
||||||
from time import time
|
from time import time
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
|
||||||
from modules.logging import logWrite
|
from modules.logging import logWrite
|
||||||
from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale
|
from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale
|
||||||
@ -86,6 +87,8 @@ except ModuleNotFoundError:
|
|||||||
pid = getpid()
|
pid = getpid()
|
||||||
app = Client("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
|
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
|
# Work in progress
|
||||||
# def check_forwards(app):
|
# def check_forwards(app):
|
||||||
@ -413,23 +416,25 @@ def callback_query_unblock(app, clb): # type: ignore
|
|||||||
if configGet("post", "mode"):
|
if configGet("post", "mode"):
|
||||||
|
|
||||||
for entry in configGet("time", "posting"):
|
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():
|
# def background_task():
|
||||||
try:
|
# try:
|
||||||
while True:
|
# while True:
|
||||||
try:
|
# try:
|
||||||
schedule.run_pending()
|
# schedule.run_pending()
|
||||||
time.sleep(1)
|
# time.sleep(1)
|
||||||
except:
|
# except:
|
||||||
pass
|
# pass
|
||||||
except Exception as exp:
|
# except Exception as exp:
|
||||||
logWrite(locale("exception_occured", "console", locale=configGet("locale")).format(exp))
|
# logWrite(locale("exception_occured", "console", locale=configGet("locale")).format(exp))
|
||||||
except KeyboardInterrupt:
|
# except KeyboardInterrupt:
|
||||||
logWrite(locale("keyboard_interrupt", "console", locale=configGet("locale")))
|
# logWrite(locale("keyboard_interrupt", "console", locale=configGet("locale")))
|
||||||
if configGet("shutdown", "reports"):
|
# if configGet("shutdown", "reports"):
|
||||||
app.send_message(configGet("admin"), locale("shutdown", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
# app.send_message(configGet("admin"), locale("shutdown", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
||||||
killProc(pid)
|
# killProc(pid)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
@ -439,9 +444,9 @@ if __name__ == "__main__":
|
|||||||
if configGet("startup", "reports"):
|
if configGet("startup", "reports"):
|
||||||
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
||||||
|
|
||||||
if configGet("post", "mode"):
|
# if configGet("post", "mode"):
|
||||||
t = Thread(target=background_task)
|
# t = Thread(target=background_task)
|
||||||
t.start()
|
# t.start()
|
||||||
|
|
||||||
if configGet("submit", "mode"):
|
if configGet("submit", "mode"):
|
||||||
# Registering user commands
|
# Registering user commands
|
||||||
|
@ -1 +1,2 @@
|
|||||||
ujson
|
ujson~=5.7.0
|
||||||
|
tgcrypto~=1.2.5
|
@ -1,3 +1,3 @@
|
|||||||
schedule
|
apscheduler~=3.9.1.post1
|
||||||
pyrogram>=2.0.0
|
pyrogram~=2.0.96
|
||||||
psutil
|
psutil~=5.9.4
|
Reference in New Issue
Block a user