# -*- coding: utf-8 -*-
import urllib, json
import Tkinter
# Author: João S. O. Bueno
# License: LGPL V 3.0
def get_people_set(method, id, update=None):
url = "http://api.twitter.com/1/statuses/%s/%s.json" % (method, id)
people = set()
cursor = "-1"
while True:
data = json.loads(urllib.urlopen(url + "?cursor=%s" % cursor).read())
cursor = data["next_cursor"]
if update:
update(cursor)
these_people = set(person["screen_name"] for person in data["users"])
people.update(these_people)
if not cursor or not these_people :
break
return people
class Window():
def __init__(self):
self.tk = Tkinter.Tk()
self.tk.title("Friends which don\'t follow you")
text_frame = Tkinter.Frame(self.tk)
scroll = Tkinter.Scrollbar(text_frame)
self.text = Tkinter.Text(text_frame, bg="white", fg="black", yscrollcommand = scroll.set)
scroll["command"] = self.text.yview
self.text.pack(side="left")
scroll.pack(side="right",fill="y")
text_frame.pack()
ctrl_frame = Tkinter.Frame(self.tk)
l = Tkinter.Label(ctrl_frame, text="Twitter display name:")
self.entry = Tkinter.Entry(ctrl_frame)
button = Tkinter.Button(ctrl_frame, text="Fetch", command=self.update)
[ctrl.pack(side="left") for ctrl in (l, self.entry, button)]
ctrl_frame.pack()
def clear(self):
self.text.delete("1.0", "10000000.0")
def update(self):
self.clear()
self.text.insert("1.0", "Fetching")
self.tk.call("update")
id = self.entry.get()
friends = get_people_set("friends", id, self.status)
followers = get_people_set("followers", id, self.status)
self.clear()
self.text.insert("1.0", u"\\n".join(sorted(friends - followers)))
def status(self, *args):
self.text.insert(self.text.index("current"), ".")
self.tk.call("update")
if __name__ == "__main__":
Window()
Tkinter.mainloop()