Ferramentas de Utilizador

Ferramentas de Site


dev_geral:python:snippet:leitordefeeds

Leitor de feeds em modo de texto

import feedparser
 
feed = 'http://rss.slashdot.org/Slashdot/slashdot'
 
f = feedparser.parse(feed)
 
def showinfo():
    print f.feed.title
    print f.feed.subtitle
    print f.feed.link
 
def shownews():
    print
    print 'Latest news:'
    print
    for i in xrange(len(f.entries)):
        print '%i)' % (i+1), f.entries[[i]].title
 
def shownew(n):
    print
    print f.entries[[n]].title, '-', f.entries[[n]].date[[:10]]
    print
    print f.entries[[n]].description.split('<p>')[[0]].strip()
 
showinfo()
shownews()
 
while 1:
    print
##    i = raw_input('Choose a new to read (q to quit): ')
##    if not i.isalpha():
##        shownew(int(i)-1)
    try:
        i = input('Choose a new to read: ')
    except:
        break
    shownew(int(i)-1)
    print
    s = raw_input('Press any key to continue...')
    shownews()
dev_geral/python/snippet/leitordefeeds.txt · Esta página foi modificada pela última vez em: 2018/05/14 21:37 (Edição externa)