BO 1.31+3 lang_sync

This commit is contained in:
Tibor Bossanyi (Freelancer) 2021-10-20 17:15:00 +02:00
parent 3123406c49
commit 49eb29b325

View File

@ -1,6 +1,7 @@
import requests import requests
import logging import logging
from django.db import connections from django.db import connections
from django.contrib import messages
import datetime import datetime
import os import os
@ -19,7 +20,7 @@ class Mautic:
'SELECT * from customer WHERE trial_date < "' + tenDays + '" and trial_date is not null') 'SELECT * from customer WHERE trial_date < "' + tenDays + '" and trial_date is not null')
def syncLang(self): 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 = logging.getLogger(__name__)
logger.info("Syncronising lang...") logger.info("Syncronising lang...")
@ -41,9 +42,15 @@ class Mautic:
response = requests.post(form_url, data=data.encode('utf-8'), headers=headers) response = requests.post(form_url, data=data.encode('utf-8'), headers=headers)
print(customer.email + " " +str(response.status_code)) 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 index = index + 1
logger.info("Syncronised customer count: " + str(index)) print( "Syncronised customer count: " + str(index))
return True return True