Store files in month directory

This commit is contained in:
Grégory Soutadé 2014-11-27 14:11:47 +01:00
parent f7bf2e11ba
commit ce4bca056d
7 changed files with 35 additions and 26 deletions

View File

@ -1,3 +1,4 @@
import os
class DisplayHTMLBlock(object): class DisplayHTMLBlock(object):
@ -56,7 +57,13 @@ class DisplayHTMLPage(object):
self.blocks.append(block) self.blocks.append(block)
def build(self, root): def build(self, root):
f = open(root + self.filename, 'w') filename = root + self.filename
base = os.path.dirname(filename)
if not os.path.exists(base):
os.makedirs(base)
f = open(filename, 'w')
f.write('<html><title>%s</title><body>' % (self.title)) f.write('<html><title>%s</title><body>' % (self.title))
for block in self.blocks: for block in self.blocks:
block.build(f) block.build(f)

16
iwla.py
View File

@ -77,11 +77,17 @@ class IWLA(object):
def isValidForCurrentAnalysis(self, request): def isValidForCurrentAnalysis(self, request):
cur_time = self.meta_infos['start_analysis_time'] cur_time = self.meta_infos['start_analysis_time']
return (time.mktime(cur_time) <= time.mktime(request['time_decoded'])) # Analyse not started
if not cur_time: return False
return (time.mktime(cur_time) < time.mktime(request['time_decoded']))
def hasBeenViewed(self, request): def hasBeenViewed(self, request):
return int(request['status']) in conf.viewed_http_codes return int(request['status']) in conf.viewed_http_codes
def getCurDisplayRoot(self):
cur_time = self.meta_infos['last_time']
return '%d/%d/' % (cur_time.tm_year, cur_time.tm_mon)
def _clearMeta(self): def _clearMeta(self):
self.meta_infos = { self.meta_infos = {
'last_time' : None 'last_time' : None
@ -93,7 +99,7 @@ class IWLA(object):
return self.display return self.display
def getDBFilename(self, time): def getDBFilename(self, time):
return (conf.DB_ROOT + '%d/%d_%s') % (time.tm_year, time.tm_mon, conf.DB_FILENAME) return (conf.DB_ROOT + '%d/%d/%s') % (time.tm_year, time.tm_mon, conf.DB_FILENAME)
def _serialize(self, obj, filename): def _serialize(self, obj, filename):
base = os.path.dirname(filename) base = os.path.dirname(filename)
@ -214,14 +220,14 @@ class IWLA(object):
def getDisplayIndex(self): def getDisplayIndex(self):
cur_time = self.meta_infos['last_time'] cur_time = self.meta_infos['last_time']
filename = '%d/index_%d.html' % (cur_time.tm_year, cur_time.tm_mon) filename = '%s/index.html' % (self.getCurDisplayRoot())
return self.display.getPage(filename) return self.display.getPage(filename)
def _generateDisplayDaysStat(self): def _generateDisplayDaysStat(self):
cur_time = self.meta_infos['last_time'] cur_time = self.meta_infos['last_time']
title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year) title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year)
filename = '%d/index_%d.html' % (cur_time.tm_year, cur_time.tm_mon) filename = '%s/index.html' % (self.getCurDisplayRoot())
print '==> Generate display (%s)' % (filename) print '==> Generate display (%s)' % (filename)
page = DisplayHTMLPage(title, filename) page = DisplayHTMLPage(title, filename)
@ -367,7 +373,7 @@ class IWLA(object):
self.analyse_started = True self.analyse_started = True
else: else:
if not self.analyse_started: if not self.analyse_started:
if not self.isValidForCurrentAnalysis(hit): if time.mktime(t) < time.mktime(cur_time):
return False return False
else: else:
self.analyse_started = True self.analyse_started = True

View File

@ -15,11 +15,10 @@ class IWLADisplayAllVisits(IPlugin):
last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True) last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True)
cur_time = self.iwla.getCurTime() title = time.strftime('All visits - %B %Y', self.iwla.getCurTime())
title = time.strftime('All visits - %B %Y', cur_time)
filename = 'all_visits_%d.html' % (cur_time.tm_mon) filename = 'all_visits.html'
path = '%d/%s' % (cur_time.tm_year, filename) path = '%s/%s' % (self.iwla.getCurDisplayRoot(), filename)
page = DisplayHTMLPage(title, path) page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen'])

View File

@ -54,8 +54,8 @@ class IWLADisplayReferers(IPlugin):
cur_time = self.iwla.getCurTime() cur_time = self.iwla.getCurTime()
title = time.strftime('Connexion from - %B %Y', cur_time) title = time.strftime('Connexion from - %B %Y', cur_time)
filename = 'referers_%d.html' % (cur_time.tm_mon) filename = 'referers.html'
path = '%d/%s' % (cur_time.tm_year, filename) path = '%s/%s' % (self.iwla.getCurDisplayRoot(), filename)
page = DisplayHTMLPage(title, path) page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits']) table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits'])
@ -93,8 +93,8 @@ class IWLADisplayReferers(IPlugin):
# All key phrases in a file # All key phrases in a file
title = time.strftime('Key Phrases - %B %Y', cur_time) title = time.strftime('Key Phrases - %B %Y', cur_time)
filename = 'key_phrases_%d.html' % (cur_time.tm_mon) filename = 'key_phrases.html'
path = '%d/%s' % (cur_time.tm_year, filename) path = '%s/%s' % (self.iwla.getCurDisplayRoot(), filename)
page = DisplayHTMLPage(title, path) page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search']) table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search'])

View File

@ -22,11 +22,10 @@ class IWLADisplayTopDownloads(IPlugin):
table.appendRow([uri, entrance]) table.appendRow([uri, entrance])
index.appendBlock(table) index.appendBlock(table)
cur_time = self.iwla.getCurTime() title = time.strftime('Top Downloads - %B %Y', self.iwla.getCurTime())
title = time.strftime('Top Downloads - %B %Y', cur_time)
filename = 'top_downloads_%d.html' % (cur_time.tm_mon) filename = 'top_downloads.html'
path = '%d/%s' % (cur_time.tm_year, filename) path = '%s/%s' % (self.iwla.getCurDisplayRoot(), filename)
page = DisplayHTMLPage(title, path) page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit']) table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit'])

View File

@ -22,11 +22,10 @@ class IWLADisplayTopHits(IPlugin):
table.appendRow([uri, entrance]) table.appendRow([uri, entrance])
index.appendBlock(table) index.appendBlock(table)
cur_time = self.iwla.getCurTime() title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
title = time.strftime('All Hits - %B %Y', cur_time)
filename = 'top_hits_%d.html' % (cur_time.tm_mon) filename = 'top_hits.html'
path = '%d/%s' % (cur_time.tm_year, filename) path = '%s/%s' % (self.iwla.getCurDisplayRoot(), filename)
page = DisplayHTMLPage(title, path) page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Top Hits', ['URI', 'Entrance']) table = DisplayHTMLBlockTable('Top Hits', ['URI', 'Entrance'])

View File

@ -22,11 +22,10 @@ class IWLADisplayTopPages(IPlugin):
table.appendRow([uri, entrance]) table.appendRow([uri, entrance])
index.appendBlock(table) index.appendBlock(table)
cur_time = self.iwla.getCurTime() title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
title = time.strftime('All Pages - %B %Y', cur_time)
filename = 'top_pages_%d.html' % (cur_time.tm_mon) filename = 'top_pages.html'
path = '%d/%s' % (cur_time.tm_year, filename) path = '%s/%s' % (self.iwla.getCurDisplayRoot(), filename)
page = DisplayHTMLPage(title, path) page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Top Pages', ['URI', 'Entrance']) table = DisplayHTMLBlockTable('Top Pages', ['URI', 'Entrance'])