Compare commits
No commits in common. "6c28df7617c46c9a3b0a4e2d72513ac395197b94" and "2b7ad0c72438f3421d1fc4ec5b8c583ecfe56969" have entirely different histories.
6c28df7617
...
2b7ad0c724
|
@ -95,7 +95,7 @@ def start_task(task_id: int):
|
||||||
add_to_group_task.delay(task_id=task_id)
|
add_to_group_task.delay(task_id=task_id)
|
||||||
|
|
||||||
case 'parse':
|
case 'parse':
|
||||||
parse_users_task.run(task_id=task_id)
|
parse_users_task.apply(task_id=task_id)
|
||||||
delete_task(task_id)
|
delete_task(task_id)
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import datetime
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
import asyncio
|
import asyncio
|
||||||
from telethon.tl.types import UserStatusOnline, UserStatusOffline
|
from app.models.session import Session
|
||||||
|
|
||||||
from app.models.user import User
|
from app.models.user import User
|
||||||
|
|
||||||
from paper.parser import PaperParser
|
from paper.parser import PaperParser
|
||||||
from app.models.task import Task
|
from app.models.task import Task
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
@ -55,17 +54,7 @@ def parse_users_task(self, task_id: int):
|
||||||
)
|
)
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
if not user.username and user.bot:
|
if not user.username:
|
||||||
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
|
continue
|
||||||
|
|
||||||
if not User.exist(user.username, collection):
|
if not User.exist(user.username, collection):
|
||||||
|
|
|
@ -12,8 +12,8 @@ class User(db.Model):
|
||||||
first_name: Mapped[str] = mapped_column(nullable=True)
|
first_name: Mapped[str] = mapped_column(nullable=True)
|
||||||
last_name: Mapped[str] = mapped_column(nullable=True)
|
last_name: Mapped[str] = mapped_column(nullable=True)
|
||||||
|
|
||||||
phone: Mapped[str] = mapped_column(nullable=True)
|
phone: Mapped[str] = mapped_column(nullable=True, unique=True)
|
||||||
username: Mapped[str] = mapped_column(nullable=True)
|
username: Mapped[str] = mapped_column(nullable=True, unique=True)
|
||||||
|
|
||||||
collection_id = Column(Integer, ForeignKey("collection.id"))
|
collection_id = Column(Integer, ForeignKey("collection.id"))
|
||||||
collection: Mapped["Collection"] = relationship("Collection", back_populates="users")
|
collection: Mapped["Collection"] = relationship("Collection", back_populates="users")
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
"""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 ###
|
|
Loading…
Reference in New Issue