Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions python/stathat.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import urllib
import urllib2
import urllib.error
import urllib.parse
import urllib.request

class StatHat:

def http_post(self, path, data):
pdata = urllib.urlencode(data)
req = urllib2.Request('http://api.stathat.com' + path, pdata)
resp = urllib2.urlopen(req)
return resp.read()
class StatHat:

def post_value(self, user_key, stat_key, value, timestamp=None):
args = {'key': stat_key, 'ukey': user_key, 'value': value}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/v', args)
def http_post(self, path, data):
pdata = urllib.parse.urlencode(data).encode("utf-8")
req = urllib.request.Request('http://api.stathat.com' + path, pdata)
resp = urllib.request.urlopen(req)
return resp.read()

def post_count(self, user_key, stat_key, count, timestamp=None):
args = {'key': stat_key, 'ukey': user_key, 'count': count}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/c', args)
def post_value(self, user_key, stat_key, value, timestamp=None):
args = {'key': stat_key, 'ukey': user_key, 'value': value}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/v', args)

def ez_post_value(self, ezkey, stat_name, value, timestamp=None):
args = {'ezkey': ezkey, 'stat': stat_name, 'value': value}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/ez', args)
def post_count(self, user_key, stat_key, count, timestamp=None):
args = {'key': stat_key, 'ukey': user_key, 'count': count}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/c', args)

def ez_post_count(self, ezkey, stat_name, count, timestamp=None):
args = {'ezkey': ezkey, 'stat': stat_name, 'count': count}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/ez', args)
def ez_post_value(self, ezkey, stat_name, value, timestamp=None):
args = {'ezkey': ezkey, 'stat': stat_name, 'value': value}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/ez', args)

def ez_post_count(self, ezkey, stat_name, count, timestamp=None):
args = {'ezkey': ezkey, 'stat': stat_name, 'count': count}
if timestamp is not None:
args['t'] = timestamp
return self.http_post('/ez', args)