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