Skip to content

Instantly share code, notes, and snippets.

@david-torres
Created October 29, 2011 22:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-torres/1325168 to your computer and use it in GitHub Desktop.
Save david-torres/1325168 to your computer and use it in GitHub Desktop.
Simple Python interface for Clicky web analytics API
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)
@tdiem
Copy link

tdiem commented Dec 28, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment