-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwitter-notify.py
84 lines (75 loc) · 2.05 KB
/
twitter-notify.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
usr="username" # username
pwd="password" # password
wait=15 # in seconds
################################################################################
##
## Info:
## Twitter notifications daemon
##
## Dependencies:
## python-twitter
## http://code.google.com/p/python-twitter/
## (apt-get install python-twitter)
##
## Run:
## python twitter-notify.py
## (from Run prompt or Session/start-up programs)
## python twitter-notify.py &
## (from command line. just don't close out the terminal window)
##
## actual daemon will happen soon enough
##
## Copyright 2009 James Wilson
##
## Author:
## James Wilson <[email protected]>
## http://ja.meswilson.com/blog/
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License version 3, as published
## by the Free Software Foundation.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranties of
## MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
## PURPOSE. See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program. If not, see <http://www.gnu.org/licenses/>.
##
################################################################################
import twitter
import time
import pynotify
if not pynotify.init ("icon-summary-body"):
sys.exit(1)
api = 0
def login():
global api, usr, pwd
try:
api = twitter.Api(username=usr, password=pwd)
except:
time.sleep(15)
return login()
login()
all = []
def notify(usr,message,icon="notification-message-IM"):
n = pynotify.Notification (usr,message,icon)
n.show()
while 1:
try:
stat = api.GetFriendsTimeline()
except:
time.sleep(15)
login()
else:
if len(all) == 0:
for s in stat:
all.append(s.text)
for s in stat:
if not s.text in all:
notify(s.user.screen_name, s.text)
all.append(s.text)
time.sleep(wait)
# print [s.text for s in stat]