def sync_data_from_mailchimp(**kwargs):
 key = request.args.get('key')
 if (key == settings.MAILCHIMP_WEBHOOK_SECRET_KEY):
  r = request
  action = r.values['type']
  list_name = mailchimp_utils.get_list_name_from_id(list_id=r.values['data[list_id]'])
  username = r.values['data[email]']
  try:
   user = User.find_one(Q('username', 'eq', username))
  except NoResultsFound:
   sentry.log_exception()
   sentry.log_message('A user with this username does not exist.')
   raise HTTPError(404, data=dict(message_short='User not found', message_long='A user with this username does not exist'))
  if (action == 'unsubscribe'):
   user.mailchimp_mailing_lists[list_name] = False
   user.save()
  elif (action == 'subscribe'):
   user.mailchimp_mailing_lists[list_name] = True
   user.save()
 else:
  raise HTTPError(http.UNAUTHORIZED)

def sync_data_from_mailchimp ( ** kwargs ) : key = request . args . get ( 'key' ) if ( key == settings . MAILCHIMP_WEBHOOK_SECRET_KEY ) : r = request action = r . values [ 'type' ] list_name = mailchimp_utils . get_list_name_from_id ( list_id = r . values [ 'data[list_id]' ] ) username = r . values [ 'data[email]' ] try : user = User . find_one ( Q ( 'username' , 'eq' , username ) ) except NoResultsFound : sentry . log_exception ( ) sentry . log_message ( 'A user with this username does not exist.' ) raise HTTPError ( 404 , data = dict ( message_short = 'User not found' , message_long = 'A user with this username does not exist' ) ) if ( action == 'unsubscribe' ) : user . mailchimp_mailing_lists [ list_name ] = False user . save ( ) elif ( action == 'subscribe' ) : user . mailchimp_mailing_lists [ list_name ] = True user . save ( ) else : raise HTTPError ( http . UNAUTHORIZED )
endpoint that the mailchimp webhook sends its data to .