Robo_Feed I am new to python, I was trying to develop a theft that took the last post from some news portals here in my region. With a search I came to the conclusion that it would be easier to do with the python feedparser module. So I'll try to explain the code ...
As I said I'm new and inexperienced, more eager to learn to program right in Python
code
import feedparser
import time
import base64
timeaut = 15
class Robo_Feed(object):
def __init__(self):
self.data = []
self.sites= {}
self.allheadlines = []
def append_url(self, name, site):
self.sites[name] = (site)
def encrip(self, published):
self.data.append(base64.b64encode(published))
def feed_parser():
def parseRSS(rss_url):
return feedparser.parse(rss_url)
def getHeadlines(rss_url):
robo.headlines = []
feed = parseRSS(rss_url)
if (base64.b64encode(feed.entries[0].published)) in str(robo.data):
return robo.headlines
else:
POSTAGEN = '*'+feed['feed']['title']+'*' +"\n" + feed.entries[0].title + "\n" + feed.entries[0].link + "\n\r"
print (POSTAGEN)
robo.encrip(feed.entries[0].published)
return robo.headlines
for key, url in robo.sites.items():
robo.allheadlines.extend(getHeadlines(url))
robo = Robo_Feed()
robo.append_url('Oglobo', 'http://oglobo.globo.com/rss.xml?secao=ece_frontpage')
robo.append_url('ZeroHora', 'http://zh.clicrbs.com.br/rs/ultimas-noticias-rss/')
try:
while True:
feed_parser()
time.sleep(time)
except KeyboardInterrupt:
print "Umteromped"
Error
File "/home/ubuntu/PycharmProjects/BotTelegran/testes.py", line 38, in <module>
feed_parser()
File "/home/ubuntu/PycharmProjects/BotTelegran/testes.py", line 30, in feed_parser
robo.allheadlines.extend(getHeadlines(url))
File "/home/ubuntu/PycharmProjects/BotTelegran/testes.py", line 22, in getHeadlines
if (base64.b64encode(feed.entries[0].published)) in str(robo.data):
IndexError: list index out of range