From 601bb0246a082ad28eac88629dc06084fae20e8a Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Fri, 16 Oct 2009 03:01:28 -0400 Subject: [PATCH] twython.reportSpam() is now included, and it *should* work, but for some reason I'm getting constant 404's at the moment whenever I try to use it (even outside of Twython, the calls seem to fail...). This'll be migrated to Twython3k once I'm sure it's actually working - would love for people to test this out and make sure I'm not an idiot. ;) --- twython.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/twython.py b/twython.py index 53b9139..fc7bfdf 100644 --- a/twython.py +++ b/twython.py @@ -290,7 +290,37 @@ class setup: raise TwythonError("getUserMentions() failed with a %s error code." % `e.code`, e.code) else: raise AuthError("getUserMentions() requires you to be authenticated.") + + def reportSpam(self, id = None, user_id = None, screen_name = None): + """reportSpam(self, id), user_id, screen_name): + Report a user account to Twitter as a spam account. *One* of the following parameters is required, and + this requires that you be authenticated with a user account. + + Parameters: + id - Optional. The ID or screen_name of the user you want to report as a spammer. + user_id - Optional. The ID of the user you want to report as a spammer. Helpful for disambiguating when a valid user ID is also a valid screen name. + screen_name - Optional. The ID or screen_name of the user you want to report as a spammer. Helpful for disambiguating when a valid screen name is also a user ID. + """ + if self.authenticated is True: + # This entire block of code is stupid, but I'm far too tired to think through it at the moment. Refactor it if you care. + if id is not None or user_id is not None or screen_name is not None: + try: + apiExtension = "" + if id is not None: + apiExtension = "?id=%s" % id + if user_id is not None: + apiExtension = "?user_id=%s" % `user_id` + if screen_name is not None: + apiExtension = "?screen_name=%s" % screen_name + return simplejson.load(self.opener.open("http://twitter.com/report_spam.json" + apiExtension)) + except HTTPError, e: + raise TwythonError("reportSpam() failed with a %s error code." % `e.code`, e.code) + else: + raise TwythonError("reportSpam requires you to specify an id, user_id, or screen_name. Try again!") + else: + raise AuthError("reportSpam() requires you to be authenticated.") + def reTweet(self, id): """reTweet(id)