refCount/dtml/refCountAdd.dtml 100666 0 0 1454 7473220330 17202 0 ustar 00unknown unknown 0 0
This creates a new refCount object.
refCount/dtml/refCountCounts.dtml 100666 0 0 2026 7474103301 17760 0 ustar 00unknown unknown 0 0For
Count Full (10)
Count Domains (10)
Show results by day
Delete all data: reset
refCount/dtml/refCountEdit.dtml 100666 0 0 1302 7473646772 17415 0 ustar 00unknown unknown 0 0Edits a refCount object.
refCount/refCount.py 100666 0 0 11436 7474104033 15344 0 ustar 00unknown unknown 0 0 ############################################################################## # Copyright (c) 2002 Andy McKay # All rights reserved. # Distributed under the following license: http://www.agmweb.ca/Scripts/license/ ############################################################################## __version__ = '0.2' from Globals import HTMLFile from Acquisition import Implicit from Persistence import Persistent from AccessControl.Role import RoleManager from DateTime import DateTime from urlparse import urlparse from OFS.SimpleItem import Item from BTrees.OOBTree import OOBTree manage_addrefCountForm = HTMLFile('dtml/refCountAdd', globals()) def manage_addrefCount(self, id, title='', REQUEST=None): ''' Adds a new xml storage object ''' obj = refCount() obj.id = id obj.title = title self._setObject(id, obj) obj = self._getOb(id) if REQUEST is not None: return self.manage_main(self, REQUEST) class refCount(Item, Persistent, Implicit, RoleManager): meta_type = 'refCount' manage_edit = HTMLFile('dtml/refCountEdit', globals()) manage_count = HTMLFile('dtml/refCountCounts', globals()) manage_options = ({'label': 'Edit', 'action': 'manage_edit'},{'label': 'Counts', 'action': 'manage_count'},) + Item.manage_options __ac_permissions__=( ('View management screens', ('manage_edit', 'manage_count', 'setExcludes', 'getExcludes', 'resetAll') ), ('View', ('__call__','getTopCount','getTopDomains','getDates') ), ) def manage_afterAdd(self, *args): """ Add in stuff """ self._data = OOBTree() self._excludes=['127.0.0.1',] def __call__(self): """ Register a request """ # ooh this is bad... REQUEST = self.REQUEST if REQUEST.has_key('HTTP_REFERER'): ref = REQUEST['HTTP_REFERER'] ref.strip() if ref: for exc in self._excludes: if ref.find(exc) >= 0: return self._register(ref) def _today(self): """ Today as string """ return DateTime().Date() def _register(self, url): _t = self._today() today = self._data.get(_t, OOBTree()) count = today.get(url, 0) count += 1 today[url] = count self._data[_t] = today def getTopDomains(self, count=20, date=None): """ Get data """ if date is None: date = self._today() normalise= {} # expensive for key, value in self._data.get(date, {}).items(): k = self._urlParse(key) n = normalise.get(k, 0) n += value normalise[k] = n counter = [] for key, value in normalise.items(): counter.append([value, key]) counter.sort() counter.reverse() ret = [] for value, shorturl in counter[:count]: ret.append( { 'fullurl':'http://'+shorturl, 'shorturl':shorturl, 'count':value} ) return ret def getDates(self): """ Returns all the dates stored """ return self._data.keys() def _firstBitUrl(self, url): url = urlparse(url) return '%s://%s' % (url[0], url[1]) def _urlParse(self, url): url = urlparse(url)[1] if url[:4] == 'www.': url = url[4:] return url def getTopCount(self, count=20, date=None): """ Get data """ if date is None: date = self._today() counter = [] for key, value in self._data.get(date, {}).items(): counter.append([value, key]) counter.sort() counter.reverse() ret = [] for value, fullurl in counter[:count]: ret.append( { 'fullurl':fullurl, 'shorturl':self._urlParse(fullurl), 'count':value} ) return ret def resetAll(self, REQUEST=None): """ nukes everything """ self._data = OOBTree() if REQUEST: REQUEST.RESPONSE.redirect('manage_count') def getExcludes(self): """ Gets excludes """ return self._excludes def setExcludes(self, excludes, REQUEST=None): """ Gets excludes """ if type(excludes) == type(''): excludes = excludes.split('\n') self._excludes = [] for _e in excludes: _e.strip() if _e and _e not in self._excludes: self._excludes.append(_e) if REQUEST: REQUEST.RESPONSE.redirect('manage_count') def getDates(self): """ Gets a list of the days """ return self._data.keys() refCount/refresh.txt 100666 0 0 0 7473220506 15270 0 ustar 00unknown unknown 0 0 refCount/www/icon.gif 100666 0 0 257 7261122416 15406 0 ustar 00unknown unknown 0 0 GIF89a ! , @\PC3M:!ȁtGaڒj!3Li(vI|?n!.$a`r h"GY0ۛO ; refCount/__init__.py 100666 0 0 666 7473215771 15274 0 ustar 00unknown unknown 0 0 import refCount def initialize(context): try: # to register the product. context.registerClass(refCount.refCount, constructors = ( refCount.manage_addrefCountForm, refCount.manage_addrefCount), icon='www/icon.gif') except: import sys, traceback, string type, val, tb = sys.exc_info() sys.stderr.write(string.join(traceback.format_exception(type, val, tb), '')) del type, val, tb