Skip to content

Instantly share code, notes, and snippets.

@tdavis
Created January 31, 2009 19:08
Show Gist options
  • Save tdavis/55633 to your computer and use it in GitHub Desktop.
Save tdavis/55633 to your computer and use it in GitHub Desktop.
import subprocess
def mixpanel_log(**kwargs):
"""
A simple function for asynchronously logging to the mixpanel.com API.
This function requires `curl` and Python version 2.4 or higher.
@param **kwargs: The parameters for the logging request. For a list of
parameters see http://mixpanel.com/api/.
@return Instance of L{subprocess.Popen}
"""
# Make sure we got the required parameters
if "project" not in kwargs or "category" not in kwargs:
raise ValueError, "You are missing a required parameter. \
See http://mixpanel.com/api/."
host = "http://api.mixpanel.com/?"
params = "&".join(["%s=%s"%(k,v) for k,v in kwargs.items()])
request = host + params
print request
return subprocess.Popen(("curl",request), stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment