From 833ad1ebe8a8db1059214ebb3ab6c70326bfde77 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Wed, 3 Jun 2009 03:51:55 -0400 Subject: [PATCH] Added social graph methods, cleaned up notification methods, tired as all hell. --- tango.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/tango.py b/tango.py index d50897c..007d24d 100644 --- a/tango.py +++ b/tango.py @@ -314,9 +314,9 @@ class setup: if id is not None: apiURL = "http://twitter.com/notifications/follow/" + id + ".json" if user_id is not None: - apiURL = "http://twitter.com/notifications/follow/follow.json?user_id" + user_id + apiURL = "http://twitter.com/notifications/follow/follow.json?user_id=" + user_id if screen_name is not None: - apiURL = "http://twitter.com/notifications/follow/follow.json?screen_name" + screen_name + apiURL = "http://twitter.com/notifications/follow/follow.json?screen_name=" + screen_name try: self.opener.open(apiURL, "") except HTTPError, e: @@ -332,9 +332,9 @@ class setup: if id is not None: apiURL = "http://twitter.com/notifications/leave/" + id + ".json" if user_id is not None: - apiURL = "http://twitter.com/notifications/leave/leave.json?user_id" + user_id + apiURL = "http://twitter.com/notifications/leave/leave.json?user_id=" + user_id if screen_name is not None: - apiURL = "http://twitter.com/notifications/leave/leave.json?screen_name" + screen_name + apiURL = "http://twitter.com/notifications/leave/leave.json?screen_name=" + screen_name try: self.opener.open(apiURL, "") except HTTPError, e: @@ -344,6 +344,36 @@ class setup: else: print "notificationLeave() requires you to be authenticated." + def getFriendsIDs(self, id = None, user_id = None, screen_name = None, page = "1"): + apiURL = "" + if id is not None: + apiURL = "http://twitter.com/friends/ids/" + id + ".json" + "?page=" + page + if user_id is not None: + apiURL = "http://twitter.com/friends/ids.json?user_id=" + user_id + "&page=" + page + if screen_name is not None: + apiURL = "http://twitter.com/friends/ids.json?screen_name=" + screen_name + "&page=" + page + try: + return simplejson.load(urllib2.urlopen(apiURL)) + except HTTPError, e: + if self.debug is True: + print e.headers + print "getFriendsIDs() failed with a " + str(e.code) + " error code." + + def getFollowersIDs(self, id = None, user_id = None, screen_name = None, page = "1"): + apiURL = "" + if id is not None: + apiURL = "http://twitter.com/followers/ids/" + id + ".json" + "?page=" + page + if user_id is not None: + apiURL = "http://twitter.com/followers/ids.json?user_id=" + user_id + "&page=" + page + if screen_name is not None: + apiURL = "http://twitter.com/followers/ids.json?screen_name=" + screen_name + "&page=" + page + try: + return simplejson.load(urllib2.urlopen(apiURL)) + except HTTPError, e: + if self.debug is True: + print e.headers + print "getFollowersIDs() failed with a " + str(e.code) + " error code." + def getSearchTimeline(self, search_query, optional_page): params = urllib.urlencode({'q': search_query, 'rpp': optional_page}) # Doesn't hurt to do pages this way. *shrug* try: