Created
December 27, 2009 14:44
demo2 twitux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
# Copyright GNU/GPL 3.0 Fitorec <chanerec@gmail.com> | |
# twitterTux.py | |
# ____ _ _ .--. | |
# | __ |(_) | | ___ ____ ___ ____ | o_o | | |
# | | _ | ||_ _|/ _ \ / __// _ \ / __/ | :_/ | | |
# | __ || | | || (_) || | | __/| (__ // \ \ | |
# |_| |_| | | \___/ |_| \___/ \___( (| | ) | |
# http://fitorec.wordpress.com /'\_ _/ | |
# \___)=(___/ | |
# Creado : 22.12.2009 | |
# | |
# Descripcion: | |
# Ejemplo practico: Mostrando NUM replicas del twitter útil pa integrar al conky | |
# requiere: El modulo de twitter de python | |
# Instalación: apt-get install python-twitter python-twyt | |
# | |
# ============= Configuracion ================= | |
USER = "MiUsuario" # usuario | |
PASS = "MiPassword" #password | |
NUM = 5 #numero de replies x mostrar <=20 | |
#=============================================== | |
import pygtk | |
pygtk.require('2.0') | |
import gtk | |
import twitter | |
def img_label_box(parent, img_filename, label_text): | |
# Create box for xpm and label | |
box1 = gtk.HBox(False, 0) | |
box1.set_border_width(2) | |
# Now on to the image stuff | |
image = gtk.Image() | |
image.set_from_file(img_filename) | |
# Create a label for the button | |
label = gtk.Label(label_text) | |
label.set_justify(gtk.JUSTIFY_FILL) | |
label.set_line_wrap(True) | |
# Pack the pixmap and label into the box | |
box1.pack_start(image, False, False, 3) | |
box1.pack_start(label, False, False, 3) | |
image.show() | |
label.show() | |
return box1 | |
""" | |
def img_download(url): | |
dom = url[url.find("//")+2:url.find("com/")]+"com" | |
img_path = "."+url[url.find("/profile")+len("/profile_images"):] | |
print os.path.isfile(img_path) | |
print dom | |
print img_path | |
conn = httplib.HTTPConnection(dom) | |
conn.request ("GET", '/' + img_path) | |
r = conn.getresponse() | |
fichero = file( "./cache/thumbnails" + '/' + "pic.jpg", "wb") | |
fichero.write(r.read()) | |
fichero.close() | |
""" | |
class Labels: | |
def __init__(self): | |
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
self.window.connect("destroy", lambda w: gtk.main_quit()) | |
self.window.set_title("TwittTux") | |
vbox = gtk.VBox(False, 5) | |
hbox = gtk.HBox(False, 5) | |
#api = twitter.Api(username = USER , password = PASS) | |
#replies = api.GetReplies() | |
""" Create a new hbox with the appropriate homogeneous """ | |
menu_bar = gtk.MenuBar() | |
vbox.pack_start(menu_bar, gtk.FALSE, gtk.FALSE, 2) | |
menu_bar.show() | |
root_menu = gtk.MenuItem("twettTux 0.0.1 Alpha") | |
root_menu.show() | |
menu_bar.append (root_menu) | |
""" replies """ | |
self.window.add(hbox) | |
hbox.pack_start(vbox, False, False, 0) | |
self.window.set_border_width(5) | |
api = twitter.Api(username = USER , password = PASS) | |
replies = api.GetReplies() | |
for rep in replies: | |
frame = gtk.Frame("@"+rep.user.screen_name) | |
print "\n@"+rep.user.screen_name | |
print "id"+str(rep.user.id) | |
label = img_label_box(self.window, rep.user.profile_image_url, rep.text) | |
button = gtk.Button() | |
button.add(label) | |
frame.add(button) | |
vbox.pack_start(frame, False, False, 0) | |
# Create a new hbox with the appropriate homogeneou | |
vbox = gtk.VBox(False, 5) | |
hbox.pack_start(vbox, False, False, 0) | |
timeLine = api.GetUserTimeline(USER) | |
for rep in timeLine: | |
frame = gtk.Frame("@"+rep.user.screen_name) | |
print "\n@"+rep.user.screen_name | |
print "id"+str(rep.user.id) | |
label = img_label_box(self.window, rep.user.profile_image_url, rep.text) | |
button = gtk.Button() | |
button.add(label) | |
frame.add(button) | |
vbox.pack_start(frame, False, False, 0) | |
# Create a new hbox with the appropriate homogeneous | |
vbox = gtk.VBox(False, 5) | |
hbox.pack_start(vbox, False, False, 0) | |
mds = api.GetDirectMessages() | |
for msg in mds: | |
#sender_screen_name | |
frame = gtk.Frame("@"+msg.sender_screen_name) | |
#img_download(rep.user.profile_image_url) | |
label = img_label_box(self.window, "caution.png", msg.text) | |
button = gtk.Button() | |
button.add(label) | |
frame.add(button) | |
vbox.pack_start(frame, False, False, 0) | |
self.window.show_all() | |
def main(): | |
gtk.main() | |
return 0 | |
if __name__ == "__main__": | |
Labels() | |
#ventana.replies() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment