iwla

iwla Git Source Tree

Root/plugins/display/feeds.py

1# -*- coding: utf-8 -*-
2#
3# Copyright Grégory Soutadé 2015
4
5# This file is part of iwla
6
7# iwla is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# iwla is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with iwla. If not, see <http://www.gnu.org/licenses/>.
19#
20
21from iwla import IWLA
22from iplugin import IPlugin
23from display import *
24from plugins.post_analysis.feeds import IWLAPostAnalysisFeeds
25
26"""
27Display hook
28
29Display feeds parsers
30
31Plugin requirements :
32 None
33
34Conf values needed :
35 create_all_feeds_page*
36
37Output files :
38 OUTPUT_ROOT/year/month/index.html
39 OUTPUT_ROOT/year/month/all_feeds.html
40
41Statistics creation :
42 None
43
44Statistics update :
45 None
46
47Statistics deletion :
48 None
49"""
50
51class IWLADisplayFeeds(IPlugin):
52 def __init__(self, iwla):
53 super(IWLADisplayFeeds, self).__init__(iwla)
54 self.API_VERSION = 1
55 self.requires = ['IWLAPostAnalysisFeeds']
56
57 def load(self):
58 self.create_all_feeds_page = self.iwla.getConfValue('create_all_feeds_page', True)
59
60 return True
61
62 def hook(self):
63 display = self.iwla.getDisplay()
64 hits = self.iwla.getCurrentVisists()
65 nb_feeds_parsers = 0
66
67 # All in a page
68 if self.create_all_feeds_page:
69 title = createCurTitle(self.iwla, self.iwla._(u'All Feeds parsers'))
70 filename = 'all_feeds.html'
71 path = self.iwla.getCurDisplayPath(filename)
72 display_visitor_ip = self.iwla.getConfValue('display_visitor_ip', False)
73
74 page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
75 table = display.createBlock(DisplayHTMLBlockTable, self.iwla._(u'All feeds parsers'), [self.iwla._(u'Host'), self.iwla._(u'Pages'), self.iwla._(u'Hits')])
76 table.setColsCSSClass(['', 'iwla_page', 'iwla_hit'])
77 for super_hit in hits.values():
78 if not super_hit['feed_parser']: continue
79 nb_feeds_parsers += 1
80 address = super_hit['remote_addr']
81 if display_visitor_ip and\
82 super_hit.get('dns_name_replaced', False):
83 address = '%s [%s]' % (address, super_hit['remote_ip'])
84 if super_hit['feed_parser'] == IWLAPostAnalysisFeeds.MERGED_FEED_PARSER:
85 address += '*'
86 if super_hit['robot']:
87 table.appendRow([address, super_hit['not_viewed_pages'], super_hit['not_viewed_hits']])
88 else:
89 table.appendRow([address, super_hit['viewed_pages'], super_hit['viewed_hits']])
90 page.appendBlock(table)
91 note = DisplayHTMLRaw(self.iwla, ('<small>*%s</small>' % (self.iwla._('Merged feeds parsers'))))
92 page.appendBlock(note)
93 display.addPage(page)
94
95 # Found in index
96 title = self.iwla._(u'Feeds parsers')
97 if self.create_all_feeds_page:
98 link = '<a href=\'%s\'>%s</a>' % (filename, self.iwla._(u'Details'))
99 title = '%s - %s' % (title, link)
100
101 index = self.iwla.getDisplayIndex()
102
103 table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._(u'Found')])
104 table.appendRow([nb_feeds_parsers])
105 index.appendBlock(table)

Archive Download this file

Branches

Tags