def mix_panel_queue(request): # The default Mixpanel consumer will take # endpoints and messages and send them to Mixpanel consumer = Consumer() with open("MIXPANEL_LOG.txt", "r+") as read_log: for line in read_log: (endpoint, message) = line.split('::', 1) consumer.send(endpoint, message) return HttpResponse(json.dumps({'success': True}), content_type='application/json')
def __init__(self): # init the client ID and config if it doesn't exist if not CONFIG_FILE.exists(): self.client_id = str(uuid.uuid4()) self.update_config() else: self.load_config() # send updated user-level properties self.mp = None if self.enabled: try: self.mp = Mixpanel( MIXPANEL_TOKEN, consumer=Consumer(request_timeout=int(TIMEOUT))) self.mp.people_set( self.client_id, { "datahub_version": datahub_package.nice_version_name(), "os": platform.system(), "python_version": platform.python_version(), }, ) except Exception as e: logger.debug(f"Error connecting to mixpanel: {e}")
def __init__(self): # try loading the config if it exists, update it if that fails if not CONFIG_FILE.exists() or not self.load_config(): # set up defaults self.client_id = str(uuid.uuid4()) self.enabled = self.enabled & ENV_ENABLED self.update_config() # send updated user-level properties self.mp = None if self.enabled: try: self.mp = Mixpanel( MIXPANEL_TOKEN, consumer=Consumer(request_timeout=int(TIMEOUT))) except Exception as e: logger.debug(f"Error connecting to mixpanel: {e}")
def __init__(self): # init the client ID and config if it doesn't exist if not CONFIG_FILE.exists(): self.client_id = str(uuid.uuid4()) self.update_config() else: self.load_config() # send updated user-level properties self.mp = None if self.enabled: try: self.mp = Mixpanel( MIXPANEL_TOKEN, consumer=Consumer(request_timeout=int(TIMEOUT))) except Exception as e: logger.debug(f"Error connecting to mixpanel: {e}")
def handle (self, data, address): print('Got %r' % data) consumer = Consumer() consumer.send(*loads(data))
try: from uwsgidecorators import spool except ImportError: # Running using Flask in dev; just run everything synchronously. class spool(object): def __init__(self, func): self.func = func def spool(self, **args): assert app.debug self.func(args) MIXPANEL_EVENT = 'SERVER' _consumer_impl = Consumer() @spool def _send_event_task(args): """ Actually sends the MixPanel event. Runs in a uwsgi worker process. """ endpoint = args['endpoint'] json_message = args['json_message'] _consumer_impl.send(endpoint, json_message) class AsyncConsumer(object): """ Forwards MixPanel events to a task running in a background process.
def __init__(self): self._consumer = Consumer() self._executor = ThreadPoolExecutor(max_workers=1)
def send_mixpanel(): consumer = Consumer() consumer.send(request.args['endpoint'], request.args['data']) return '', 200
#from django.core.signals import request_finished from django.contrib.auth.signals import user_logged_in from django.db.models.signals import pre_save, post_save, post_delete from django.dispatch import receiver from django.core.mail import send_mail from django.core.mail import EmailMultiAlternatives from django.conf import settings from mixpanel import Mixpanel, Consumer from .models import CustomUser, Invitation, EmailVerification, PasswordResetRequest mp = Mixpanel(settings.MIXPANEL_PROJECT_TOKEN, Consumer(verify_cert=False)) @receiver(pre_save) def lower_email_addresses(sender, instance, **kwargs): if isinstance(instance, CustomUser): email = getattr(instance, 'email', None) if email: instance.email = email.lower() @receiver(post_save) def send_invitation_email(sender, instance, created, **kwargs): if created and isinstance(instance, Invitation): subject, from_email, to = 'You have been invited to %s' % ( settings.SITE_DOMAIN ), '*****@*****.**', instance.invited_email_address text_content = """