Skip to content

Commit

Permalink
broadcast_next_meme_to_active_more_than_days_ago
Browse files Browse the repository at this point in the history
  • Loading branch information
ohld committed Jun 6, 2024
1 parent f791b46 commit f8bde4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/broadcasts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,15 @@ async def get_users_with_language(
WHERE language_code = '{language_code}'
"""
return await fetch_all(text(select_query))


async def get_users_active_more_than_days_ago(
days_ago: int,
):
select_query = f"""
SELECT id
FROM "user"
WHERE last_active_at < NOW() - INTERVAL '{days_ago} DAYS'
AND type != 'blocked_bot'
"""
return await fetch_all(text(select_query))
8 changes: 8 additions & 0 deletions src/flows/broadcasts/meme.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from src.broadcasts.service import (
get_users_active_minutes_ago,
get_users_active_more_than_days_ago,
)
from src.recommendations.meme_queue import check_queue, get_next_meme_for_user
from src.recommendations.service import create_user_meme_reaction
Expand Down Expand Up @@ -67,3 +68,10 @@ async def broadcast_next_meme_to_active_1w_ago():
async def broadcast_next_meme_to_active_4w_ago():
users = await get_users_active_minutes_ago(4 * 7 * 24 * 60, 4 * 7 * 24 * 60 + 60)
await broadcast_next_meme_to_users(users)


@flow
async def broadcast_next_meme_to_active_more_than_days_ago(days: int = 3):
"""To call manually sometimes"""
users = await get_users_active_more_than_days_ago(days)
await broadcast_next_meme_to_users(users)

0 comments on commit f8bde4c

Please sign in to comment.