-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup scheduled management command to collect weekly stats on documen…
…tation forums
- Loading branch information
1 parent
1489335
commit 2f81498
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash -l | ||
|
||
# Collect Daily Matomo Stats | ||
|
||
# | ||
# About clever cloud cronjobs: | ||
# https://www.clever-cloud.com/doc/tools/crons/ | ||
# | ||
|
||
if [[ "$INSTANCE_NUMBER" != "0" ]]; then | ||
echo "Instance number is ${INSTANCE_NUMBER}. Stop here." | ||
exit 0 | ||
fi | ||
|
||
# $APP_HOME is set by default by clever cloud. | ||
cd $APP_HOME | ||
|
||
python manage.py collect_matomo_forum_stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
lacommunaute/stats/management/commands/collect_matomo_forum_stats.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from datetime import date | ||
|
||
from dateutil.relativedelta import relativedelta | ||
from django.core.management.base import BaseCommand | ||
|
||
from lacommunaute.stats.models import ForumStat | ||
from lacommunaute.utils.date import get_last_sunday | ||
from lacommunaute.utils.matomo import collect_forum_stats_from_matomo_api | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Collecter les stats des forum dans matomo, jusqu'au dimanche précédent l'execution" | ||
|
||
def handle(self, *args, **options): | ||
period = "week" | ||
|
||
from_date = ForumStat.objects.filter(period=period).order_by("-date").first() | ||
|
||
if from_date: | ||
from_date = from_date.date + relativedelta(days=7) | ||
else: | ||
from_date = date(2023, 10, 2) | ||
|
||
to_date = get_last_sunday(date.today()) | ||
|
||
collect_forum_stats_from_matomo_api(from_date=from_date, to_date=to_date, period=period) | ||
|
||
self.stdout.write(self.style.SUCCESS("That's all, folks!")) |