Feeds : display last access date for merged feed parsers

This commit is contained in:
Gregory Soutade 2023-01-28 09:36:48 +01:00
parent 3a8c667fdc
commit 9c57ad3ece
2 changed files with 17 additions and 9 deletions

View File

@ -88,7 +88,10 @@ class IWLADisplayFeeds(IPlugin):
address += ' *'
pages = super_hit['not_viewed_pages'][0] + super_hit['viewed_pages'][0]
hits = super_hit['not_viewed_hits'][0] + super_hit['viewed_hits'][0]
table.appendRow([address, pages, hits, time.asctime(super_hit['last_access'])])
last_access = super_hit.get('feed_parser_last_access', None)
if not last_access:
last_access = super_hit['last_access']
table.appendRow([address, pages, hits, time.asctime(last_access)])
page.appendBlock(table)
note = DisplayHTMLRaw(self.iwla, ('<small>*%s</small>' % (self.iwla._(u'Merged feeds parsers'))))
page.appendBlock(note)

View File

@ -30,6 +30,9 @@ Find feeds parsers (first hit in feeds conf value and no viewed pages if it's a
If merge_feeds_parsers is set to True, merge feeds parsers with the same user agent
as it must be the same person with a different IP address.
Warning : When merge_feeds_parsers is activated, last access display date is the more
recent date of all merged parsers found
Plugin requirements :
None
@ -101,24 +104,26 @@ class IWLAPostAnalysisFeeds(IPlugin):
if self.merged_feeds.get(key, None) is None:
# Merged
self.merged_feeds[key] = hit
else:
elif hit['remote_ip'] != self.merged_feeds[key]['remote_ip']:
# Next time
# Current must be ignored
hit['feed_parser'] = self.NOT_A_FEED_PARSER
last_access = hit['last_access']
# Previous matched hit must be set as merged
isFeedParser = self.MERGED_FEED_PARSER
hit = self.merged_feeds[key]
if hit['last_access'] < last_access:
hit['feed_parser_last_access'] = last_access
else:
hit['feed_parser_last_access'] = hit['last_access']
hit['feed_parser'] = isFeedParser
def mergeFeedsParsers(self, isFeedParser, hit):
if isFeedParser:
# One hit only match
if True or (hit['viewed_hits'][0] + hit['not_viewed_hits'][0]) == 1:
for r in self.merge_feeds_parsers_list:
if r.match(hit['remote_addr']) or r.match(hit['remote_ip']):
#print('hit match %s' % (hit['remote_addr']))
self._appendToMergeCache(isFeedParser, r, hit)
return
for r in self.merge_feeds_parsers_list:
if r.match(hit['remote_addr']) or r.match(hit['remote_ip']):
self._appendToMergeCache(isFeedParser, r, hit)
return
#print("No match for %s : %d" % (hit['remote_addr'], hit['viewed_hits'][0] + hit['not_viewed_hits'][0]))
# Other cases, look for user agent
user_agent = hit['requests'][0]['http_user_agent'].lower()