document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # -*- coding: utf-8 -*-
  2. import urllib, json
  3. import Tkinter
  4. # Author: João S. O. Bueno
  5. # License: LGPL V 3.0
  6.  
  7.  
  8. def get_people_set(method, id, update=None):
  9.     url = "http://api.twitter.com/1/statuses/%s/%s.json"  % (method, id)
  10.     people = set()
  11.     cursor = "-1"
  12.     while True:
  13.         data = json.loads(urllib.urlopen(url + "?cursor=%s" % cursor).read())
  14.         cursor = data["next_cursor"]
  15.         if update:
  16.             update(cursor)
  17.         these_people = set(person["screen_name"] for person in data["users"])
  18.         people.update(these_people)
  19.         if not cursor  or not these_people :
  20.             break
  21.     return people
  22.  
  23. class Window():
  24.     def __init__(self):
  25.         self.tk = Tkinter.Tk()
  26.         self.tk.title("Friends which don\'t follow you")
  27.         text_frame = Tkinter.Frame(self.tk)
  28.         scroll = Tkinter.Scrollbar(text_frame)
  29.         self.text = Tkinter.Text(text_frame, bg="white", fg="black", yscrollcommand = scroll.set)
  30.         scroll["command"] = self.text.yview
  31.         self.text.pack(side="left")
  32.         scroll.pack(side="right",fill="y")
  33.         text_frame.pack()
  34.         ctrl_frame = Tkinter.Frame(self.tk)
  35.         l = Tkinter.Label(ctrl_frame, text="Twitter display name:")
  36.         self.entry = Tkinter.Entry(ctrl_frame)
  37.         button = Tkinter.Button(ctrl_frame, text="Fetch", command=self.update)
  38.         [ctrl.pack(side="left") for ctrl in (l, self.entry, button)]
  39.         ctrl_frame.pack()
  40.     def clear(self):
  41.         self.text.delete("1.0", "10000000.0")
  42.     def update(self):
  43.         self.clear()
  44.         self.text.insert("1.0", "Fetching")
  45.         self.tk.call("update")
  46.         id = self.entry.get()
  47.         friends = get_people_set("friends", id, self.status)
  48.         followers = get_people_set("followers", id, self.status)
  49.         self.clear()
  50.         self.text.insert("1.0", u"\\n".join(sorted(friends - followers)))
  51.     def status(self, *args):
  52.         self.text.insert(self.text.index("current"), ".")
  53.         self.tk.call("update")
  54.  
  55. if __name__ == "__main__":
  56.     Window()
  57.     Tkinter.mainloop()
');