add timer for bot crawl that appears in debug log

This commit is contained in:
Egg 2024-10-09 16:14:29 +02:00
parent d7aea928d1
commit f4edfba532

View file

@ -5,7 +5,7 @@ from config import config
from db import db from db import db
import logging import logging
from sendmail import sendmail from sendmail import sendmail
from time import sleep from time import sleep, time
def shutdown(): def shutdown():
try: try:
@ -34,14 +34,16 @@ if __name__ == '__main__':
while True: while True:
sleep(15) # rest 15 seconds between each crawl run sleep(15) # rest 15 seconds between each crawl run
for user in db.active_users: for user in db.active_users:
sleep(1)
for bot in bots: for bot in bots:
timer_crawl = time()
reports = bot.crawl(user) reports = bot.crawl(user)
logger.debug("Crawl using bot %s took %f seconds" % (bot, time()-timer_crawl))
for status in reports: for status in reports:
if not user.is_appropriate(status): if not user.is_appropriate(status):
logger.info("Inaproppriate message: %d %s %s" % (user.uid, status.author, status.text)) logger.info("Inaproppriate message: %d %s %s" % (user.uid, status.author, status.text))
continue continue
for bot2 in bots: for bot2 in bots:
sleep(1)
bot2.post(user, status) bot2.post(user, status)
logger.info("Resent: %d %s %s" % (user.uid, status.author, status.text)) logger.info("Resent: %d %s %s" % (user.uid, status.author, status.text))
except Exception: except Exception: