Attachment 'PageHits1.2.1.py'

Download

   1 #format Python
   2 """
   3     0.xx first version without a number
   4     0.2  do not display non-existing pages
   5     2004-03-24 Eventlogger call embedded
   6 """
   7 
   8 # Imports
   9 import string
  10 from MoinMoin import config, wikiutil
  11 from MoinMoin.Page import Page
  12 from MoinMoin.eventlog import EventLogger
  13 
  14 #from MoinMoin.i18n import _
  15 
  16 
  17 def execute(macro, args):
  18     ev = EventLogger()
  19     data=ev.read(['VIEWPAGE'])
  20     pagehits={}
  21     for event in data:
  22         page = event[2]['pagename']
  23         try:
  24             pagehits[page]=pagehits[page]+1
  25         except:
  26             pagehits[page]=1
  27 
  28     # get hits and sort them
  29     hits = []
  30     for pagehit in pagehits.items():
  31         if Page(pagehit[0]).exists():
  32             hits.append((pagehit[1],pagehit[0]))
  33     hits.sort()
  34     hits.reverse()
  35 
  36     # format list
  37     result = macro.formatter.number_list(1)
  38     for hit, page in hits:
  39         result = (result + macro.formatter.listitem(1) +
  40             macro.formatter.code(1) +
  41             string.replace("%6d" % hit, " ", " ") + " " +
  42             macro.formatter.code(0) +
  43             macro.formatter.pagelink(page) +
  44             macro.formatter.listitem(0)
  45         )
  46     result = result + macro.formatter.number_list(0)
  47 
  48     return result
  49 
  50 #

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2003-12-07 18:15:54, 1.3 KB) [[attachment:MacroMarket-PageHits.py]]
  • [get | view] (2008-01-29 20:55:04, 1.5 KB) [[attachment:PageHits.py]]
  • [get | view] (2008-01-29 20:55:10, 1.3 KB) [[attachment:PageHits1.2.1.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.