Noticias

Para leer noticias sobre seguimos los siguientes pasos:

1) Importar librería para el Newtwork News Transfer Protocol

from nntplib import *

2) Crear el servidor

URL_FREE_NETWORK_NEWS_SERVER = 'web.aioe.org'
server = NNTP( URL_FREE_NETWORK_NEWS_SERVER )

3) Definir los parámetros para conectar con el servidor

(resp, count, first, last, name) = server.group('comp.lang.python')
  • resp - Response del servidor
  • count - Nº de noticias cargadas
  • first - Nº de la 1ª noticia
  • last - Nº de la última noticia
  • name - Nombre de la noticia

4) Pedirle al servidor que rango / tipo de noticias hay

(resp, subs) = server.xhdr('subject', (str(first)+'-'+str(last) ) )
  • subs - Géneros Por ejemplo muestro los 10 últimos por pantalla y elijo cual quiero ver
    for subject in subs[-10:]:
    print(subject)
    number = input('Elija artículo')
    
    5) Mostrar artículo por pantalla
    (reply, num, id, list) = server.body(str(number))
    for line in list:
    print(line)
    
  • reply -
  • num -
  • id -
  • list - La noticia en sí

results matching ""

    No results matching ""