Twitter_Notify.PY

Bueno pues, en una de estas veces que andaba aburrido dije, me fastidia entrar al Twitter o estarle dando F5, o sea ni que fuera yo qué. Así que decidí hacer una app. Sé que seguramente hay más y mejores, pero no importa, el punto es que la quize hacer yo y pues ahí vamos, la ando mejorando. La primera versión solo era un globo y esta versión ya tiene botoncitos hihi, uno de ellos responder que te lleva directo a la página para un reply al tweet =)

Totalmente hecho con python y libnotify.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pynotify
import pycurl
import simplejson
import time
import os
import pygtk
import gtk

pygtk.require('2.0')

= "der_ketzer"
= "********"
filename = '/home/derketzer/.Twitter_id'

file = open(filename, 'r')
id = file.readline()
file.close()

class Test:
def __init__(self):
self.contents = ''

def body_callback(self, buf):
self.contents = self.contents + buf

t = Test()
c = pycurl.Curl();

c.setopt(c.URL, 'http://www.twitter.com/statuses/friends_timeline.json?since_id='+id);

c.setopt(c.USERPWD, u+":"+p);

c.setopt(c.WRITEFUNCTION, t.body_callback);
c.perform();
c.close();

json = simplejson.loads(t.contents)

def default_cb(n, action):
id = int(action)

os.system("firefox http://twitter.com/?status=@"+json[id]['user']['screen_name']+"%20&in_reply_to_status_id="+str(json[id]['id'])+"&in_reply_to="+json[id]['user']['screen_name'])

n.close()
gtk.main_quit()

paso = 0

if len(json) != 0:
pynotify.init("Twitter messages")

json.reverse()

id = json[len(json)-1]['id']

for text in json:
pynotify.init ("Twitter Notify")
n = pynotify.Notification(text['user']['screen_name']+" dijo:"+text['text'])
n.set_urgency(pynotify.URGENCY_NORMAL)
#n.set_timeout(30000) #20 segundos
#n.set_category("device")
n.add_action(str(paso), "Responder", default_cb)
n.show()
paso += 1

file = open(filename, 'w')
file.write(str(id))
file.close()

gtk.main()

Y bueno, todo funciona con un archivo llamado .Twitter_id que guarda al final del chequeo el id del último mensaje, para la próxima vez que visite Twitter, cheque a partir de ese ID

1
3462859311

Saludos

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

*