9 sys.stderr.write("usage: cidnotify SERVER\n")
13 pynotify.init("cidnotify")
25 signal.signal(signal.SIGCHLD, signal.SIG_IGN)
28 acfile = open(os.getenv("HOME") + "/phone/actab")
35 actab += [(line[:pos], line[pos + 1:].strip())]
38 for family, socktype, proto, canonname, sockaddr in socket.getaddrinfo(server, 5001, 0, socket.SOCK_STREAM):
40 sk = socket.socket(family, socktype, proto)
49 sys.stderr.write("cidnotify: could not connect to " + server + "\n");
59 os.execvp(cmd[0], cmd)
68 os.kill(t2n[0], signal.SIGINT)
75 global notif, curnum, lastring
86 if num[:len(ac)] == ac:
92 return "<i>Undisclosed number</i>"
93 text = "<b>Number</b>: " + curnum + "\n"
96 text += "<b>Area code</b>: " + acn + "\n"
98 text += "<b>Area code</b>: <i>Unknown</i>\n"
100 text += "<b>Name</b>: <i>Looking up...</i>\n"
102 text += "<b>Name</b>: <i>No hits</i>\n"
104 text += "<b>Name</b>: " + name + "\n"
108 global curnum, t2n, notif, lastring
111 notif = pynotify.Notification("Phone call", notiftext())
116 t2n = popen("tel2name", num)
123 if lastring is not None:
124 timeout = lastring + 10 - time()
127 fds = reduce(lambda s, l: s | set(l),
128 select.select(fds, [], fds, timeout),
131 if sk.fileno() in fds:
133 if ret == "": sys.exit(0)
135 lines = buf.split("\n")
137 for line in lines[:-1]:
141 if lastring is not None:
144 if t2n is not None and t2n[1] in fds:
145 ret = os.read(t2n[1], 100)
149 name = namebuf.strip()
151 if notif is not None:
152 notif.update("Phone call", notiftext())
155 if lastring is not None and lastring + 10 < time():
158 except KeyboardInterrupt: