diff --git a/core_examples/public_timeline.py b/core_examples/public_timeline.py deleted file mode 100644 index da28e7e..0000000 --- a/core_examples/public_timeline.py +++ /dev/null @@ -1,8 +0,0 @@ -from twython import Twython - -# Getting the public timeline requires no authentication, huzzah -twitter = Twython() -public_timeline = twitter.getPublicTimeline() - -for tweet in public_timeline: - print tweet["text"] diff --git a/setup.py b/setup.py index 0e1adb7..eeb5832 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( include_package_data=True, # Package dependencies. - install_requires=['simplejson', 'requests>=0.13.9'], + install_requires=['simplejson', 'requests>=0.14.1'], # Metadata for PyPI. author='Ryan McGrath', diff --git a/twython/twitter_endpoints.py b/twython/twitter_endpoints.py index aeb9941..9bc6806 100644 --- a/twython/twitter_endpoints.py +++ b/twython/twitter_endpoints.py @@ -160,9 +160,13 @@ api_table = { 'method': 'POST', }, 'myTotals': { - 'url' : '/account/totals.json', + 'url': '/account/totals.json', 'method': 'GET', }, + 'removeProfileBanner': { + 'url': '/account/remove_profile_banner.json', + 'method': 'POST', + }, # Favorites methods 'getFavorites': { diff --git a/twython/twython.py b/twython/twython.py index 3fa2b5d..535ecec 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -185,15 +185,14 @@ class Twython(object): 'content': content, } - # wrap the json loads in a try, and defer an error # why? twitter will return invalid json with an error code in the headers json_error = False try: content = simplejson.loads(content) except ValueError: - json_error= True - content= {} + json_error = True + content = {} if response.status_code > 304: # If there is no error message, use a default. @@ -210,8 +209,8 @@ class Twython(object): error_code=response.status_code, retry_after=response.headers.get('retry-after')) - # if we have a json error here , then it's not an official TwitterAPI error - if json_error: + # if we have a json error here, then it's not an official TwitterAPI error + if json_error and not response.status_code in (200, 201, 202): raise TwythonError('Response was not valid JSON, unable to decode.') return content @@ -400,8 +399,24 @@ class Twython(object): for tweet in self.searchGen(search_query, **kwargs): yield tweet + def bulkUserLookup(self, **kwargs): + """Stub for a method that has been deprecated, kept for now to raise errors + properly if people are relying on this (which they are...). + """ + warnings.warn( + "This function has been deprecated. Please migrate to .lookupUser() - params should be the same.", + DeprecationWarning, + stacklevel=2 + ) + # The following methods are apart from the other Account methods, # because they rely on a whole multipart-data posting function set. + + ## Media Uploading functions ############################################## + + def _media_update(self, url, file_, **params): + return self.post(url, params=params, files=file_) + def updateProfileBackgroundImage(self, file_, tile=True, version=1): """Updates the authenticating user's profile background image. @@ -417,16 +432,6 @@ class Twython(object): {'image': (file_, open(file_, 'rb'))}, **{'tile': tile}) - def bulkUserLookup(self, **kwargs): - """Stub for a method that has been deprecated, kept for now to raise errors - properly if people are relying on this (which they are...). - """ - warnings.warn( - "This function has been deprecated. Please migrate to .lookupUser() - params should be the same.", - DeprecationWarning, - stacklevel=2 - ) - def updateProfileImage(self, file_, version=1): """Updates the authenticating user's profile image (avatar). @@ -453,8 +458,22 @@ class Twython(object): {'media': (file_, open(file_, 'rb'))}, **params) - def _media_update(self, url, file_, **params): - return self.post(url, params=params, files=file_) + def updateProfileBannerImage(self, file_, version=1, **params): + """Updates the users profile banner + + :param file_: (required) A string to the location of the file + :param version: (optional) A number, default 1 because that's the + only API version Twitter has now + + **params - You may pass items that are taken in this doc + (https://dev.twitter.com/docs/api/1/post/account/update_profile_banner) + """ + url = 'https://api.twitter.com/%d/account/update_profile_banner.json' % version + return self._media_update(url, + {'banner': (file_, open(file_, 'rb'))}, + **params) + + ########################################################################### def getProfileImageUrl(self, username, size='normal', version=1): """Gets the URL for the user's profile image.