This commit is contained in:
Tibor Bossanyi (Freelancer)
2021-12-01 00:24:31 +01:00
parent 3a429e714b
commit a18112cf5e
11 changed files with 500 additions and 58 deletions
@@ -52,6 +52,40 @@ class Mautic:
print( "Syncronised customer count: " + str(index))
return True
def syncTrial(self):
qs = Customer.objects.raw('SELECT * from customer WHERE trial_date is not null and trial_date_sync is null')
logger = logging.getLogger(__name__)
logger.info("Syncronising trial date...")
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[trialdate]=" + str(customer.trial_date) + \
"&mauticform[formId]=3" + \
"&mauticform[formName]=appdatachange"
print(data)
form_url = 'https://mautic.aitrainer.app/form/submit?formId=3'
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 trial_date_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 sync(self):