Skip to content

Instantly share code, notes, and snippets.

@thorikawa
Created October 12, 2015 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thorikawa/dd57547aef8d36525b6d to your computer and use it in GitHub Desktop.
Save thorikawa/dd57547aef8d36525b6d to your computer and use it in GitHub Desktop.
モジュール追加などなしでPepperからmixpanelにイベントデータを送るためのボックス用スクリプト
import urllib2, json, base64, calendar, time
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
#put initialization code here
pass
def onUnload(self):
#put clean-up code here
pass
def onInput_onStart(self):
try:
token = self.getParameter("token")
event = self.getParameter("event")
now = int(calendar.timegm(time.gmtime()))
props = {
"time": now,
"token": token
}
data = {
"event": event,
"properties": props
}
data = json.dumps(data)
b64data = base64.b64encode(data)
url = "http://api.mixpanel.com/track/?data=" + b64data
self.logger.info("Sending... %s" % url)
urllib2.urlopen(url)
self.onStopped()
except urllib2.URLError, message:
self.logger.warn("Failed to open: %s, message=%s" % (url, message))
self.onFailed(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment