From 49eb29b325df8ad005bc8ed2ae5ad5d93a8f3c5a Mon Sep 17 00:00:00 2001 From: "Tibor Bossanyi (Freelancer)" Date: Wed, 20 Oct 2021 17:15:00 +0200 Subject: [PATCH] BO 1.31+3 lang_sync --- aitrainer_backoffice/controlling/automation/mautic.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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