Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion funnel/cli/periodic/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ async def user_stats() -> dict[str, ResourceStats]:
return stats


async def projects_stats() -> list[models.Project]:
"""Fetch all the projects that have been created in the last 24 hours."""

tz = pytz.timezone(app.config['TIMEZONE'])
now = utcnow().astimezone(tz)
today = midnight_to_utc(now)
new_projects = models.Project.query.filter(
models.Project.created_at >= today,
).all()
return new_projects


# --- Commands -------------------------------------------------------------------------


Expand All @@ -384,7 +396,9 @@ async def dailystats() -> None:
now = utcnow().astimezone(tz)
display_date = now - relativedelta(days=1)

user_data, matomo_data = await asyncio.gather(user_stats(), matomo_stats())
user_data, matomo_data, project_data = await asyncio.gather(
user_stats(), matomo_stats(), projects_stats()
)
message = (
f"*Traffic #statistics for {display_date.strftime('%a, %-d %b %Y')}*\n"
f"\n"
Expand Down Expand Up @@ -447,6 +461,11 @@ async def dailystats() -> None:
for mdata in matomo_data.socials:
message += f"{mdata.nb_visits}: {mdata.label.strip()}\n"

if project_data:
message += "\n*New projects:*\n"
for project in project_data:
message += f"→ [{project.joined_title}]({project.url_for()})\n"

bot = telegram.Bot(app.config["TELEGRAM_STATS_APIKEY"])
await bot.send_message(
text=message,
Expand Down