import requests from mixpanel import Mixpanel from django.conf import settings from django.contrib.auth import get_user_model from project.celery import app @app.task def user_to_mixpanel(user_id, email, phone, first_name, last_name, date_joined, role, subscriptions): mix = Mixpanel(settings.MIX_TOKEN) mix.people_set( user_id, { '$email': email, '$phone': phone, '$first_name': first_name, '$last_name': last_name, '$created': date_joined, 'role': role, 'subscriptions': subscriptions, } ) @app.task def users_to_roistat(): User = get_user_model() users_queryset = User.objects.all() users = [ { 'id': str(user.id), 'name': user.get_full_name(), 'phone': str(user.phone), 'email': user.email, 'birth_date': user.birthday.strftime('%d%m%Y') if user.birthday else None, } for user in users_queryset ] project = settings.ROISTAT_PROJECT key = settings.ROISTAT_KEY url = settings.ROISTAT_API_URL + f'/project/clients/import?key={key}&project={project}' resp = requests.post(url, json=users)