Compare commits

...

3 Commits

4 changed files with 51 additions and 6 deletions

View File

@ -95,7 +95,7 @@ def start_task(task_id: int):
add_to_group_task.delay(task_id=task_id)
case 'parse':
parse_users_task.apply(task_id=task_id)
parse_users_task.run(task_id=task_id)
delete_task(task_id)
return '', 204

View File

@ -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):

View File

@ -12,8 +12,8 @@ class User(db.Model):
first_name: Mapped[str] = mapped_column(nullable=True)
last_name: Mapped[str] = mapped_column(nullable=True)
phone: Mapped[str] = mapped_column(nullable=True, unique=True)
username: Mapped[str] = mapped_column(nullable=True, unique=True)
phone: Mapped[str] = mapped_column(nullable=True)
username: Mapped[str] = mapped_column(nullable=True)
collection_id = Column(Integer, ForeignKey("collection.id"))
collection: Mapped["Collection"] = relationship("Collection", back_populates="users")

View File

@ -0,0 +1,34 @@
"""phone and username not unique
Revision ID: 11ed77b4dbe8
Revises: d573f6529ad5
Create Date: 2024-03-09 22:59:14.088171
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '11ed77b4dbe8'
down_revision = 'd573f6529ad5'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_constraint('user_phone_key', type_='unique')
batch_op.drop_constraint('user_username_key', type_='unique')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.create_unique_constraint('user_username_key', ['username'])
batch_op.create_unique_constraint('user_phone_key', ['phone'])
# ### end Alembic commands ###