@@ -0,0 +1,1859 @@
+%22%22%22Display latests news from a website%22%22%22%0A%0A# PYTHON STUFFS #######################################################%0A%0Aimport datetime%0Aimport re%0Afrom urllib.parse import urljoin%0A%0Afrom bs4 import BeautifulSoup%0A%0Afrom nemubot.exception import IRCException%0Afrom nemubot.hooks import hook%0Afrom nemubot.tools import web%0A%0Afrom more import Response%0Afrom nemubot.tools.feed import Feed, AtomEntry%0A%0A%0A# HELP ################################################################%0A%0Adef help_full():%0A    return %22Display the latests news from a given URL: !news URL%22%0A%0A%0A# MODULE CORE #########################################################%0A%0Adef find_rss_links(url):%0A    soup = BeautifulSoup(web.getURLContent(url))%0A    for rss in soup.find_all('link', attrs=%7B%22type%22: re.compile(%22%5Eapplication/atom%22)%7D):%0A        yield urljoin(url, rss%5B%22href%22%5D)%0A%0Adef get_last_news(url):%0A    feed = Feed(web.getURLContent(url))%0A    return feed.entries%0A%0A%0A# MODULE INTERFACE ####################################################%0A%0A@hook(%22cmd_hook%22, %22news%22)%0Adef cmd_news(msg):%0A    if not len(msg.args):%0A        raise IRCException(%22Indicate the URL to visit.%22)%0A%0A    url = %22 %22.join(msg.args)%0A    links = %5Bx for x in find_rss_links(url)%5D%0A    if len(links) == 0: links = %5B url %5D%0A%0A    res = Response(channel=msg.channel, nomore=%22No more news from %25s%22 %25 url)%0A    for n in get_last_news(links%5B0%5D):%0A        res.append_message(%22%25s published %25s: %25s %25s%22 %25 ((%22%5Cx02%22 + web.striphtml(n.title) + %22%5Cx0F%22) if n.title else %22An article without title%22,%0A                                                       (n.updated.strftime(%22on %25A %25d. %25B %25Y at %25H:%25M%22) if n.updated else %22someday%22) if isinstance(n, AtomEntry) else n.pubDate,%0A                                                       web.striphtml(n.summary) if n.summary else %22%22,%0A                                                       n.link if n.link else %22%22))%0A    return res%0A

Introduce new module News: it fetchs atom feed from a website and display it