BO 1.34+6 no data sync

This commit is contained in:
Tibor Bossanyi (Freelancer)
2021-12-02 17:59:28 +01:00
parent 67ac1e1ddd
commit c98528d5f0
4 changed files with 84 additions and 1 deletions
@@ -13,6 +13,75 @@ else:
class Mautic:
def syncNoDataOldDownloaders(self):
qs = Customer.objects.raw('SELECT * FROM customer c left join exercises e on c.customer_id = e.customer_id WHERE trial_date_sync <= NOW() - INTERVAL 2 DAY AND e.exercise_id is null AND c.last_exercise_sync is null')
logger = logging.getLogger(__name__)
logger.info("Syncronising lang...")
headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache"
}
index = 0
for customer in qs:
data = "mauticform[email]=" + customer.email + \
"&mauticform[database_id]=" + str(customer.customer_id) + \
"&mauticform[lastexercise]=1900-01-01" + \
"&mauticform[formId]=7" + \
"&mauticform[formName]=appdatasync"
print(data)
form_url = 'https://mautic.aitrainer.app/form/submit?formId=7'
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 last_exercise_sync = NOW() WHERE customer_id="
+ str(customer.customer_id))
print(f'customer {customer.customer_id} is updated')
index = index + 1
print( "Syncronised customer count: " + str(index))
return True
def syncNoDataNewSubscribes(self):
qs = Customer.objects.raw('SELECT * FROM customer c left join exercises e on c.customer_id = e.customer_id WHERE c.date_add <= NOW() - INTERVAL 2 DAY AND e.exercise_id is null AND c.last_exercise_sync is null')
logger = logging.getLogger(__name__)
logger.info("Syncronising lang...")
headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache"
}
index = 0
for customer in qs:
data = "mauticform[email]=" + customer.email + \
"&mauticform[database_id]=" + str(customer.customer_id) + \
"&mauticform[lastexercise]=1900-01-01" + \
"&mauticform[formId]=7" + \
"&mauticform[formName]=appdatasync"
print(data)
form_url = 'https://mautic.aitrainer.app/form/submit?formId=7'
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 last_exercise_sync = NOW() WHERE customer_id="
+ str(customer.customer_id))
print(f'customer {customer.customer_id} is updated')
index = index + 1
print( "Syncronised customer count: " + str(index))
return True
def syncLang(self):
qs = Customer.objects.raw('SELECT * from customer WHERE lang is not null and lang_sync is null')