-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Brevo): Commande pour synchroniser toutes les semaines les entre…
…prises (SIAE) (#1106)
- Loading branch information
Showing
6 changed files
with
64 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,22 @@ | ||
#!/bin/bash -l | ||
|
||
# Sync with Brevo CRM (Siae companies, ...) | ||
|
||
# Do not run if this env var is not set: | ||
if [[ -z "$CRON_CRM_BREVO_SYNC_ENABLED" ]]; then | ||
echo "CRON_CRM_BREVO_SYNC_ENABLED not set. Exiting..." | ||
exit 0 | ||
fi | ||
|
||
# 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 | ||
|
||
django-admin crm_brevo_sync |
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
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 |
---|---|---|
|
@@ -147,6 +147,8 @@ | |
"lemarche.stats", | ||
# CMS (Wagtail) | ||
"lemarche.cms", | ||
# Brevo CRM | ||
"lemarche.crm", | ||
] | ||
|
||
WAGTAIL_APPS = [ | ||
|
Empty file.
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,38 @@ | ||
import time | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
|
||
from lemarche.siaes.models import Siae | ||
from lemarche.utils.apis import api_brevo | ||
from lemarche.utils.commands import BaseCommand | ||
|
||
|
||
ten_days_ago = timezone.now() - timedelta(days=10) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
(Weekly) script to send Siae to Brevo CRM (companies) | ||
Usage: | ||
python manage.py crm_brevo_sync | ||
""" | ||
|
||
def handle(self, **options): | ||
self.stdout.write("-" * 80) | ||
self.stdout.write("Script to sync with Brevo CRM...") | ||
|
||
# SIAE --> companies | ||
# Update only the recently updated | ||
siaes_qs = Siae.objects.filter(updated_at__gte=ten_days_ago) | ||
progress = 0 | ||
|
||
self.stdout.write( | ||
f"Companies: updating our {Siae.objects.count()} siaes. {siaes_qs.count()} recently updated." | ||
) | ||
for siae in siaes_qs: | ||
api_brevo.create_or_update_company(siae) | ||
progress += 1 | ||
if (progress % 10) == 0: # avoid API rate-limiting | ||
time.sleep(1) |
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