Skip to content

Commit

Permalink
Added new projects to daily stats
Browse files Browse the repository at this point in the history
  • Loading branch information
djamg committed Oct 17, 2023
1 parent c7040af commit 0cae1b4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion funnel/cli/periodic/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,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 @@ -386,7 +398,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 @@ -449,6 +463,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

0 comments on commit 0cae1b4

Please sign in to comment.