From 5520fe020434378518aa6e6fb3cf15aa6b76c567 Mon Sep 17 00:00:00 2001 From: winet Date: Sat, 9 Mar 2024 23:12:27 +1000 Subject: [PATCH] filter users by activity --- app/blueprints/api/tasks/tasks.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/blueprints/api/tasks/tasks.py b/app/blueprints/api/tasks/tasks.py index 255dee8..3722ab8 100644 --- a/app/blueprints/api/tasks/tasks.py +++ b/app/blueprints/api/tasks/tasks.py @@ -1,10 +1,11 @@ +import datetime import time from celery import shared_task import asyncio -from app.models.session import Session -from app.models.user import User +from telethon.tl.types import UserStatusOnline, UserStatusOffline +from app.models.user import User from paper.parser import PaperParser from app.models.task import Task from app.extensions import db @@ -54,7 +55,17 @@ def parse_users_task(self, task_id: int): ) for user in users: - if not user.username: + if not user.username and user.bot: + continue + + is_active = False + if isinstance(user.status, UserStatusOffline): + is_active = user.status.was_online + datetime.timedelta(day=5) >= datetime.now() + + if isinstance(user.status, UserStatusOnline): + is_active = True + + if not is_active: continue if not User.exist(user.username, collection):