2014-11-26 16:17:16 +01:00
|
|
|
import time
|
|
|
|
|
|
|
|
from iwla import IWLA
|
|
|
|
from iplugin import IPlugin
|
|
|
|
from display import *
|
|
|
|
|
|
|
|
class IWLADisplayReferers(IPlugin):
|
|
|
|
def __init__(self, iwla):
|
|
|
|
super(IWLADisplayReferers, self).__init__(iwla)
|
|
|
|
self.API_VERSION = 1
|
2014-11-26 21:06:36 +01:00
|
|
|
self.requires = ['IWLAPostAnalysisReferers']
|
2014-11-26 16:17:16 +01:00
|
|
|
|
2014-11-26 20:31:13 +01:00
|
|
|
def hook(self):
|
2014-11-26 21:06:36 +01:00
|
|
|
month_stats = self.iwla.getMonthStats()
|
|
|
|
referers = month_stats.get('referers', {})
|
|
|
|
robots_referers = month_stats.get('robots_referers', {})
|
|
|
|
search_engine_referers = month_stats.get('search_engine_referers', {})
|
|
|
|
key_phrases = month_stats.get('key_phrases', {})
|
2014-11-26 16:17:16 +01:00
|
|
|
|
|
|
|
top_referers = [(k, referers[k]['pages']) for k in referers.keys()]
|
|
|
|
top_referers = sorted(top_referers, key=lambda t: t[1], reverse=True)
|
|
|
|
|
|
|
|
top_robots_referers = [(k, robots_referers[k]['pages']) for k in robots_referers.keys()]
|
|
|
|
top_robots_referers = sorted(top_robots_referers, key=lambda t: t[1], reverse=True)
|
|
|
|
|
|
|
|
top_search_engine_referers = [(k, search_engine_referers[k]['pages']) for k in search_engine_referers.keys()]
|
|
|
|
top_search_engine_referers = sorted(top_search_engine_referers, key=lambda t: t[1], reverse=True)
|
|
|
|
|
|
|
|
top_key_phrases = key_phrases.items()
|
|
|
|
top_key_phrases = sorted(top_key_phrases, key=lambda t: t[1], reverse=True)
|
|
|
|
|
2014-11-27 19:38:41 +01:00
|
|
|
cur_time = self.iwla.getCurTime()
|
2014-11-26 16:17:16 +01:00
|
|
|
index = self.iwla.getDisplayIndex()
|
|
|
|
|
|
|
|
# All referers in a file
|
|
|
|
title = time.strftime('Connexion from - %B %Y', cur_time)
|
|
|
|
|
2014-11-27 14:11:47 +01:00
|
|
|
filename = 'referers.html'
|
2014-11-27 14:29:25 +01:00
|
|
|
path = self.iwla.getCurDisplayPath(filename)
|
2014-11-26 16:17:16 +01:00
|
|
|
|
2014-11-30 19:05:17 +01:00
|
|
|
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
|
2014-11-26 16:17:16 +01:00
|
|
|
table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits'])
|
2014-11-27 21:40:23 +01:00
|
|
|
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
|
|
|
|
|
2014-11-26 16:17:16 +01:00
|
|
|
table.appendRow(['<b>Search Engine</b>', '', ''])
|
|
|
|
for r,_ in top_search_engine_referers:
|
|
|
|
row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
|
|
|
|
table.appendRow(row)
|
|
|
|
|
|
|
|
table.appendRow(['<b>External URL</b>', '', ''])
|
|
|
|
for r,_ in top_referers:
|
|
|
|
row = [r, referers[r]['pages'], referers[r]['hits']]
|
|
|
|
table.appendRow(row)
|
|
|
|
|
|
|
|
table.appendRow(['<b>External URL (robot)</b>', '', ''])
|
|
|
|
for r,_ in top_robots_referers:
|
|
|
|
row = [r, robots_referers[r]['pages'], robots_referers[r]['hits']]
|
|
|
|
table.appendRow(row)
|
|
|
|
|
|
|
|
page.appendBlock(table)
|
|
|
|
|
|
|
|
display = self.iwla.getDisplay()
|
|
|
|
display.addPage(page)
|
|
|
|
|
2014-11-27 19:38:41 +01:00
|
|
|
link = '<a href=\'%s\'>All referers</a>' % (filename)
|
|
|
|
|
|
|
|
# Top referers in index
|
|
|
|
title = '%s - %s' % ('Connexion from', link)
|
|
|
|
|
|
|
|
table = DisplayHTMLBlockTable(title, ['Origin', 'Pages', 'Hits'])
|
2014-11-27 21:40:23 +01:00
|
|
|
table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
|
|
|
|
|
2014-11-27 19:38:41 +01:00
|
|
|
table.appendRow(['<b>Search Engine</b>', '', ''])
|
|
|
|
for r,_ in top_search_engine_referers[:10]:
|
|
|
|
row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
|
|
|
|
table.appendRow(row)
|
|
|
|
|
|
|
|
table.appendRow(['<b>External URL</b>', '', ''])
|
|
|
|
for r,_ in top_referers[:10]:
|
|
|
|
row = [r, referers[r]['pages'], referers[r]['hits']]
|
|
|
|
table.appendRow(row)
|
|
|
|
|
|
|
|
table.appendRow(['<b>External URL (robot)</b>', '', ''])
|
|
|
|
for r,_ in top_robots_referers[:10]:
|
|
|
|
row = [r, robots_referers[r]['pages'], robots_referers[r]['hits']]
|
|
|
|
table.appendRow(row)
|
2014-11-26 16:17:16 +01:00
|
|
|
|
|
|
|
index.appendBlock(table)
|
|
|
|
|
|
|
|
# All key phrases in a file
|
|
|
|
title = time.strftime('Key Phrases - %B %Y', cur_time)
|
|
|
|
|
2014-11-27 14:11:47 +01:00
|
|
|
filename = 'key_phrases.html'
|
2014-11-27 14:29:25 +01:00
|
|
|
path = self.iwla.getCurDisplayPath(filename)
|
2014-11-26 16:17:16 +01:00
|
|
|
|
2014-11-30 19:05:17 +01:00
|
|
|
page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', []))
|
2014-11-26 16:17:16 +01:00
|
|
|
table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search'])
|
2014-11-27 21:40:23 +01:00
|
|
|
table.setColsCSSClass(['', 'iwla_search'])
|
2014-11-26 16:17:16 +01:00
|
|
|
for phrase in top_key_phrases:
|
|
|
|
table.appendRow([phrase[0], phrase[1]])
|
|
|
|
page.appendBlock(table)
|
|
|
|
|
|
|
|
display.addPage(page)
|
2014-11-26 19:33:08 +01:00
|
|
|
|
2014-11-27 19:38:41 +01:00
|
|
|
link = '<a href=\'%s\'>All key phrases</a>' % (filename)
|
|
|
|
|
|
|
|
# Top key phrases in index
|
|
|
|
title = '%s - %s' % ('Top key phrases', link)
|
|
|
|
table = DisplayHTMLBlockTable(title, ['Key phrase', 'Search'])
|
2014-11-27 21:40:23 +01:00
|
|
|
table.setColsCSSClass(['', 'iwla_search'])
|
2014-11-27 19:38:41 +01:00
|
|
|
for phrase in top_key_phrases[:10]:
|
|
|
|
table.appendRow([phrase[0], phrase[1]])
|
|
|
|
index.appendBlock(table)
|