Created
October 12, 2015 01:55
-
-
Save thorikawa/dd57547aef8d36525b6d to your computer and use it in GitHub Desktop.
モジュール追加などなしでPepperからmixpanelにイベントデータを送るためのボックス用スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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