diff --git a/aitrainer_backoffice/controlling/automation/mautic.py b/aitrainer_backoffice/controlling/automation/mautic.py index 4ff160f..23f653d 100644 --- a/aitrainer_backoffice/controlling/automation/mautic.py +++ b/aitrainer_backoffice/controlling/automation/mautic.py @@ -1,6 +1,7 @@ import requests import logging from django.db import connections +from django.contrib import messages import datetime import os @@ -19,7 +20,7 @@ class Mautic: 'SELECT * from customer WHERE trial_date < "' + tenDays + '" and trial_date is not null') def syncLang(self): - qs = Customer.objects.raw('SELECT * from customer WHERE lang is not null') + qs = Customer.objects.raw('SELECT * from customer WHERE lang is not null and lang_sync is null') logger = logging.getLogger(__name__) logger.info("Syncronising lang...") @@ -41,9 +42,15 @@ class Mautic: response = requests.post(form_url, data=data.encode('utf-8'), headers=headers) print(customer.email + " " +str(response.status_code)) + if response.status_code == 200: + with connections["live"].cursor() as cursor: + cursor.execute("UPDATE customer SET lang_sync = NOW() WHERE customer_id=" + + str(customer.customer_id)) + print(f'customer {customer.customer_id} is updated') + index = index + 1 - logger.info("Syncronised customer count: " + str(index)) + print( "Syncronised customer count: " + str(index)) return True