Skip to content

Commit

Permalink
Fixed news plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
tian2992 committed Sep 30, 2015
1 parent 9890d26 commit efa958d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Empty file added plugins/neonews.hy
Empty file.
44 changes: 23 additions & 21 deletions plugins/news.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import requests
import types
import re
from random import randint
from random import choice
from plugins.baseactionplugin import BaseActionPlugin
from ircmessage import IRCMessage
from plugins.lengua import _
from bs4 import BeautifulSoup

try:
import xml.etree.cElementTree as ETree
except ImportError:
import xml.etree.ElementTree as ETree

class News(BaseActionPlugin):
def __init__(self):
BaseActionPlugin.__init__(self)
self.synchronous = False
def __init__(self):
BaseActionPlugin.__init__(self)
self.synchronous = False

def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
url = 'http://hosted2.ap.org/atom/APDEFAULT/3d281c11a96b4ad082fe88aa0db04305'
def execute(self, ircMsg, userRole, *args, **kwargs):
user = ircMsg.user
m = IRCMessage()
url = 'http://feeds.reuters.com/reuters/topNews'

f = requests.get( url )
data = f.text
soup = BeautifulSoup( data )
tag = soup.find_all( 'entry' )
tagita = tag[ randint( 0, len( tag ) -1 ) ]
respuesta = tagita.title.string.encode( 'utf8') + ' | ' + tagita.link[ 'href' ].encode( 'utf8' )

m.msg = respuesta
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m
req = requests.get(url)
tree = ETree.fromstring(req.text.encode("UTF-8"))
tag_list = tree.findall("./channel/item")
tagita = choice(tag_list)
respuesta = u"{} | {}".format(tagita.find("title").text, tagita.find("link").text)


m.msg = respuesta
m.channel = ircMsg.channel
m.user = user
m.directed = True
return m

0 comments on commit efa958d

Please sign in to comment.