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

View File

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