Buscador para Twitter, con Python, en 12 líneas

Hoy estuve viendo los resultados de la búsqueda #pyconar2009 en Twitter Search, y me dije: “por qué no hacer las búsquedas desde consola, con Python?”

Unos minutos después, aquí está el resultado:

1
2
3
4
5
6
7
8
9
10
11
12
import feedparser, urllib
 
def main():
    feed_source = 'http://search.twitter.com/search.atom?%s'
    q = raw_input('Search term: ')
    if q:
        f = feedparser.parse(feed_source % urllib.urlencode({'q': q}))
        for entry in f.entries:
            print '%s: "%s"' % (entry.author, entry.title) 
 
if __name__ == '__main__':
    main()

En este caso usé Universal Feed Parser ($ sudo apt-get install python-feedparser), pero pueden utilizar la librería que más les guste :-)

1 Response to “Buscador para Twitter, con Python, en 12 líneas”


  • muy buena…yo le hize una pequeña modificacion

    import feedparser, urllib

    def main():
    feed_source = ‘http://search.twitter.com/search.atom?%s’
    q = raw_input(‘Buscar: ‘)
    if q:
    f = feedparser.parse(feed_source % urllib.urlencode({‘q’: q}))
    for entry in f.entries:
    print “###@###”
    print “”
    print ‘%s:’ % (entry.author)
    print “”
    print ‘%s:’ % (entry.title)
    print “”
    if __name__ == ‘__main__’:
    main()

Leave a Reply




This work by Patricio Molina is licensed under a Creative Commons Attribution-ShareAlike 2.5 Argentina.