lunes, enero 07, 2008

La inconclusa

Hace poco me quedé sin espacio en disco duro y al estar revisando cosas viejas encontré este pedazo de código que hice al tratar de hacer un cliente para twitter, el cual nunca acabé :P y mejor decidí usar TwitterFox. Inmediatamente se nota que es un código a medias pero funciona desde la línea de comandos.

#TwittHandler Copyright (C) 2007 by Julio Acuna
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

from xml.sax.handler import ContentHandler
from xml.sax import make_parser
import urllib2

class TwitHandler(ContentHandler):
def __init__(self):
self.StatusData = ""
self.Text = ""
self.ScrName = ""
self.ImgUrl = ""

def characters(self, text):
if self.StatusData == "screen_name":
self.ScrName = text
if self.StatusData == "text":
self.Text = text

def startElement(self, name, attrs):
self.StatusData = name

def endElement(self, name):
if self.StatusData == "screen_name":
print self.ScrName
if self.StatusData == "text":
print self.Text


th = TwitHandler()
saxparser = make_parser()
saxparser.setContentHandler(th)
uri = urllib2.urlopen("http://twitter.com/statuses/friends_timeline/urkonn.xml")
saxparser.parse(uri)

Quisiera, ahora si, hacer un cliente para Pownce ya que no existe en este momento ninguno para GNU/Linux pero no he tenido tiempo y la API de Pownce no es tan boba como la de twitter. A lo mejor en un fin de semana empiezo a escribir algo.


syntax highlighting by pygments

No hay comentarios.: