counter implemented

This commit is contained in:
+++ 2020-07-26 17:12:37 +02:00
parent 43ff022969
commit bd250ca790

View file

@ -45,8 +45,7 @@ class Plugin(Plugin):
def help(self):
return ('!dsa serves the actual debian security alerts. A given '
' number reduces the count of alerts displayed to number. '
'Not implemented at the moment.'
'number reduces the count of alerts displayed to number. '
'\nSyntax: !dsa <number>')
def run(self, stanza):
@ -65,7 +64,8 @@ class Plugin(Plugin):
if arguments is not False:
count = self.get_count(arguments[0])
if count is False:
self.callback(': '.join((muc_nick, no_count_msg)))
message = no_count_msg.format(arguments[0].strip())
self.callback(': '.join((muc_nick, message)))
return
logging.debug('Start thread for debian security alerts')
@ -124,15 +124,28 @@ class DsaThread(threading.Thread):
"purl": "http://purl.org/rss/1.0/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
}
about_list = xmldoc.xpath('//purl:item/@rdf:about', namespaces=nsmap)
for about in reversed(about_list):
if self.count is False or self.count >= len(about_list):
self.count = len(about_list)
logging.debug('Set count to {}'.format(self.count))
for about in reversed(about_list[:self.count]):
try:
dsa_id = self.get_id_from_about(about)
title = xmldoc.xpath(
'//purl:item[@rdf:about="{}"]/purl:title/text()'.format(
about), namespaces=nsmap)[0]
message = '\n'.join((message, title))
except IndexError:
break
return message
def reverse_list(self, about_list):
'''
'''
pass
def get_file(self):
'''
Fetchs the security alerts from debian.org
@ -154,6 +167,7 @@ class DsaThread(threading.Thread):
Extracts the dsa id from tehe given string.
param 1: string
'''
logging.debug('About: {}'.format(about))
return int(about.split('/')[-1].split('-')[1])