linux: use json kernel.org release feeed

Reading the releases from the json feed is much simpler and it allows us
to drop the dependency on feedparser.
This commit is contained in:
jkhsjdhjs 2022-11-08 00:25:05 +00:00
parent cb1cc4439a
commit d59e170e8b
2 changed files with 9 additions and 16 deletions

View File

@ -2,7 +2,7 @@
import random import random
import irc3 import irc3
import feedparser import requests
from docopt import Dict from docopt import Dict
from irc3.plugins.command import command from irc3.plugins.command import command
from irc3.utils import IrcString from irc3.utils import IrcString
@ -19,7 +19,7 @@ OS as defined by POSIX."""
class Linux(Plugin): class Linux(Plugin):
KERNEL_FEED = 'https://www.kernel.org/feeds/kdist.xml' KERNEL_FEED = 'https://www.kernel.org/releases.json'
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :(?:.* )?(debian|ubuntu|apt|dpkg|flash)(?: .*|$)') @irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :(?:.* )?(debian|ubuntu|apt|dpkg|flash)(?: .*|$)')
def debillian(self, target: str): def debillian(self, target: str):
@ -39,21 +39,15 @@ class Linux(Plugin):
%%kernel %%kernel
""" """
feed = feedparser.parse(self.KERNEL_FEED) try:
res = requests.get(self.KERNEL_FEED, timeout=10).json()
# Cancel if no feed or entries except requests.exceptions.RequestException:
if not feed or not feed.get('entries'): return '\x02[Kernel]\x02 Error fetching kernel.org releases'
self.log.error('Error fetching kernel.org releases feed')
return
# Make list of releases # Make list of releases
releases = [] releases = []
for e in feed['entries']: for release in res['releases']:
version, branch = e['title'].split(': ') releases.append('\x02{}\x02 ({}{})'.format(release['version'], release['moniker'],
', \x1DEOL\x1D' if release['iseol'] else ''))
if '(EOL)' in e['description']:
branch = '{}, \x1DEOL\x1D'.format(branch)
releases.append('\x02{}\x02 ({})'.format(version, branch))
return '\x02[Kernel]\x02 {}'.format(', '.join(releases)) return '\x02[Kernel]\x02 {}'.format(', '.join(releases))

View File

@ -6,6 +6,5 @@ aiocron~=1.3
psycopg2~=2.8 psycopg2~=2.8
requests~=2.22 requests~=2.22
GitPython~=3.0 GitPython~=3.0
feedparser~=6.0
python-dotenv~=0.17.1 python-dotenv~=0.17.1
lxml~=4.6 lxml~=4.6