-
-
Save david-torres/1325168 to your computer and use it in GitHub Desktop.
import requests | |
import json | |
class ClickyApi(object): | |
""" | |
A simple Python interface for the Clicky web analytics api. | |
Relies on the Requests library - python-requests.org | |
Usage: | |
YOUR_CLICKY_SITE_ID = '12345' | |
YOUR_CLICKY_SITE_KEY = 'qwerty' | |
clicky = ClickyApi(YOUR_CLICKY_SITE_ID, YOUR_CLICKY_SITE_KEY) | |
clicky.stats({ | |
'type': 'pages', | |
'date': 'today' | |
}) | |
""" | |
api_endpoint = 'http://api.getclicky.com/api/stats/4' | |
output_format = 'json' | |
site_id = '' | |
site_key = '' | |
def __init__(self, site_id, site_key, app=''): | |
self.site_id = site_id | |
self.site_key = site_key | |
self.app = app | |
def stats(self, params={}): | |
params.update({ | |
'site_id': self.site_id, | |
'sitekey': self.site_key, | |
'output': self.output_format, | |
'app': self.app | |
}) | |
r = requests.get(self.api_endpoint, params=params) | |
return json.loads(r.content) |
FYI all, this still works beautifully. I've updated the original post to bring some clarity on a few items and make it easier to run out of box. All you need to do is install requests in the virtual environment that you are using and update the INSERT_YOUR_SITE_ID_HERE and INSERT_YOUR_CLICKY_SITE_KEY_HERE. Thanks David for the original post! The formatting is extremely wonky but
import json
import requests ## This needs to be pip installed
class ClickyApi(object):
api_endpoint = 'http://api.getclicky.com/api/stats/4'
output_format = 'json'
site_id = ''
site_key = ''
def __init__(self, site_id, site_key, app=''):
self.site_id = site_id
self.site_key = site_key
self.app = app
def stats(self, params={}):
params.update({
'site_id': self.site_id,
'sitekey': self.site_key,
'output': self.output_format,
'app': self.app
})
r = requests.get(self.api_endpoint, params=params)
return json.loads(r.content)
YOUR_CLICKY_SITE_ID = INSERT_YOUR_SITE_ID_HERE # This is available on the Prefs Tab in Clicky
YOUR_CLICKY_SITE_KEY = INSERT_YOUR_CLICKY_SITE_KEY_HERE # This is available on the Prefs Tab in Clicky
clicky = ClickyApi(YOUR_CLICKY_SITE_ID, YOUR_CLICKY_SITE_KEY)
data = clicky.stats({
'type': 'pages',
'date': 'today'
})
print(data)
File "", line 1
def init(self, site_id, site_key, app=''):
^
IndentationError: unexpected indent
File "", line 1
self.site_id = 101028657
^
IndentationError: unexpected indent
File "", line 1
self.site_key = 7588ac343c560814
^
IndentationError: unexpected indent
File "", line 1
self.app = app
^
IndentationError: unexpected indent
File "", line 1
def stats(self, params={}):
^
IndentationError: unexpected indent
File "", line 1
params.update({
^
IndentationError: unexpected indent
File "", line 1
'site_id': self.site_id,
^
IndentationError: unexpected indent
File "", line 1
'sitekey': self.site_key,
^
IndentationError: unexpected indent
File "", line 1
'output': self.output_format,
^
IndentationError: unexpected indent
File "", line 1
'app': self.app
^
IndentationError: unexpected indent
File "", line 1
})
^
IndentationError: unexpected indent
File "", line 1
r = requests.get(self.api_endpoint + '?' + urlencode(params))
^
IndentationError: unexpected indent
File "", line 1
return json.loads(r.content)
^
IndentationError: unexpected indent