Removed bulkUserLookup & getProfileImageUrl, deprecating shortenUrl, raise TwythonDepWarnings in Python 2.7 >
This commit is contained in:
parent
d4c19fc3a9
commit
a451db43c1
5 changed files with 41 additions and 48 deletions
|
|
@ -22,6 +22,9 @@ just define it
|
||||||
- Headers now always include the User-Agent as Twython vXX unless User-Agent is overwritten
|
- Headers now always include the User-Agent as Twython vXX unless User-Agent is overwritten
|
||||||
- Removed senseless TwythonError thrown if method is not GET or POST, who cares -- if the user passes something other than GET or POST just let Twitter return the error that they messed up
|
- Removed senseless TwythonError thrown if method is not GET or POST, who cares -- if the user passes something other than GET or POST just let Twitter return the error that they messed up
|
||||||
- Removed conversion to unicode of (int, bool) params passed to a requests. ``requests`` isn't greedy about variables that can't be converted to unicode anymore
|
- Removed conversion to unicode of (int, bool) params passed to a requests. ``requests`` isn't greedy about variables that can't be converted to unicode anymore
|
||||||
|
- Removed `bulkUserLookup` (please use `lookupUser` instead), removed `getProfileImageUrl` (will be completely removed from Twitter API on May 7th, 2013)
|
||||||
|
- Updated shortenUrl to actually work for those using it, but it is being deprecated since `requests` makes it easy for developers to implement their own url shortening in their app (see https://github.com/ryanmcgrath/twython/issues/184)
|
||||||
|
- Twython Deprecation Warnings will now be seen in shell when using Python 2.7 and greater
|
||||||
|
|
||||||
2.7.3 (2013-04-12)
|
2.7.3 (2013-04-12)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
|
||||||
5
twython/advisory.py
Normal file
5
twython/advisory.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class TwythonDeprecationWarning(DeprecationWarning):
|
||||||
|
"""Custom DeprecationWarning to be raised when methods/variables are being deprecated in Twython.
|
||||||
|
Python 2.7 > ignores DeprecationWarning so we want to specifcally bubble up ONLY Twython Deprecation Warnings
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
@ -13,13 +13,12 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import json
|
import json
|
||||||
|
|
||||||
try:
|
|
||||||
from urlparse import parse_qsl
|
|
||||||
except ImportError:
|
|
||||||
from cgi import parse_qsl
|
|
||||||
|
|
||||||
if is_py2:
|
if is_py2:
|
||||||
from urllib import urlencode, quote_plus
|
from urllib import urlencode, quote_plus
|
||||||
|
try:
|
||||||
|
from urlparse import parse_qsl
|
||||||
|
except ImportError:
|
||||||
|
from cgi import parse_qsl
|
||||||
|
|
||||||
builtin_str = str
|
builtin_str = str
|
||||||
bytes = str
|
bytes = str
|
||||||
|
|
@ -29,7 +28,7 @@ if is_py2:
|
||||||
|
|
||||||
|
|
||||||
elif is_py3:
|
elif is_py3:
|
||||||
from urllib.parse import urlencode, quote_plus
|
from urllib.parse import urlencode, quote_plus, parse_qsl
|
||||||
|
|
||||||
builtin_str = str
|
builtin_str = str
|
||||||
str = str
|
str = str
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
"""
|
"""
|
||||||
A huge map of every Twitter API endpoint to a function definition in Twython.
|
A huge map of every Twitter API endpoint to a function definition in Twython.
|
||||||
|
|
||||||
Parameters that need to be embedded in the URL are treated with mustaches, e.g:
|
Parameters that need to be embedded in the URL are treated with mustaches, e.g:
|
||||||
|
|
||||||
{{version}}, etc
|
{{version}}, etc
|
||||||
|
|
||||||
When creating new endpoint definitions, keep in mind that the name of the mustache
|
When creating new endpoint definitions, keep in mind that the name of the mustache
|
||||||
will be replaced with the keyword that gets passed in to the function at call time.
|
will be replaced with the keyword that gets passed in to the function at call time.
|
||||||
|
|
||||||
i.e, in this case, if I pass version = 47 to any function, {{version}} will be replaced
|
i.e, in this case, if I pass version = 47 to any function, {{version}} will be replaced
|
||||||
with 47, instead of defaulting to 1.1 (said defaulting takes place at conversion time).
|
with 47, instead of defaulting to 1.1 (said defaulting takes place at conversion time).
|
||||||
|
|
||||||
This map is organized the order functions are documented at:
|
This map is organized the order functions are documented at:
|
||||||
https://dev.twitter.com/docs/api/1.1
|
https://dev.twitter.com/docs/api/1.1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
api_table = {
|
api_table = {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
warnings.simplefilter('default') # For Python 2.7 >
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests_oauthlib import OAuth1
|
from requests_oauthlib import OAuth1
|
||||||
|
|
||||||
|
from .advisory import TwythonDeprecationWarning
|
||||||
from .compat import json, urlencode, parse_qsl, quote_plus
|
from .compat import json, urlencode, parse_qsl, quote_plus
|
||||||
from .endpoints import api_table
|
from .endpoints import api_table
|
||||||
from .exceptions import TwythonError, TwythonAuthError, TwythonRateLimitError
|
from .exceptions import TwythonError, TwythonAuthError, TwythonRateLimitError
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
|
|
||||||
|
warnings.simplefilter('always', TwythonDeprecationWarning) # For Python 2.7 >
|
||||||
|
|
||||||
|
|
||||||
class Twython(object):
|
class Twython(object):
|
||||||
def __init__(self, app_key=None, app_secret=None, oauth_token=None, oauth_token_secret=None,
|
def __init__(self, app_key=None, app_secret=None, oauth_token=None, oauth_token_secret=None,
|
||||||
|
|
@ -42,14 +44,14 @@ class Twython(object):
|
||||||
if twitter_token or twitter_secret:
|
if twitter_token or twitter_secret:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
'Instead of twitter_token or twitter_secret, please use app_key or app_secret (respectively).',
|
'Instead of twitter_token or twitter_secret, please use app_key or app_secret (respectively).',
|
||||||
DeprecationWarning,
|
TwythonDeprecationWarning,
|
||||||
stacklevel=2
|
stacklevel=2
|
||||||
)
|
)
|
||||||
|
|
||||||
if callback_url:
|
if callback_url:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
'Please pass callback_url to the get_authentication_tokens method rather than Twython.__init__',
|
'Please pass callback_url to the get_authentication_tokens method rather than Twython.__init__',
|
||||||
DeprecationWarning,
|
TwythonDeprecationWarning,
|
||||||
stacklevel=2
|
stacklevel=2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -267,7 +269,7 @@ class Twython(object):
|
||||||
# ------------------------------------------------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def shortenURL(url_to_shorten, shortener='http://is.gd/api.php'):
|
def shortenURL(url_to_shorten, shortener='http://is.gd/create.php'):
|
||||||
"""Shortens url specified by url_to_shorten.
|
"""Shortens url specified by url_to_shorten.
|
||||||
Note: Twitter automatically shortens all URLs behind their own custom t.co shortener now,
|
Note: Twitter automatically shortens all URLs behind their own custom t.co shortener now,
|
||||||
but we keep this here for anyone who was previously using it for alternative purposes. ;)
|
but we keep this here for anyone who was previously using it for alternative purposes. ;)
|
||||||
|
|
@ -276,11 +278,18 @@ class Twython(object):
|
||||||
:param shortener: (optional) In case you want to use a different
|
:param shortener: (optional) In case you want to use a different
|
||||||
URL shortening service
|
URL shortening service
|
||||||
"""
|
"""
|
||||||
|
warnings.warn(
|
||||||
|
'With requests it\'s easy enough for a developer to implement url shortenting themselves. Please see: https://github.com/ryanmcgrath/twython/issues/184',
|
||||||
|
TwythonDeprecationWarning,
|
||||||
|
stacklevel=2
|
||||||
|
)
|
||||||
|
|
||||||
if shortener == '':
|
if shortener == '':
|
||||||
raise TwythonError('Please provide a URL shortening service.')
|
raise TwythonError('Please provide a URL shortening service.')
|
||||||
|
|
||||||
request = requests.get(shortener, params={
|
request = requests.get(shortener, params={
|
||||||
'query': url_to_shorten
|
'format': 'json',
|
||||||
|
'url': url_to_shorten
|
||||||
})
|
})
|
||||||
|
|
||||||
if request.status_code in [301, 201, 200]:
|
if request.status_code in [301, 201, 200]:
|
||||||
|
|
@ -290,7 +299,7 @@ class Twython(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def constructApiURL(base_url, params):
|
def constructApiURL(base_url, params):
|
||||||
return base_url + "?" + "&".join(["%s=%s" % (Twython.unicode2utf8(key), quote_plus(Twython.unicode2utf8(value))) for (key, value) in params.iteritems()])
|
return base_url + '?' + '&'.join(['%s=%s' % (Twython.unicode2utf8(key), quote_plus(Twython.unicode2utf8(value))) for (key, value) in params.iteritems()])
|
||||||
|
|
||||||
def searchGen(self, search_query, **kwargs):
|
def searchGen(self, search_query, **kwargs):
|
||||||
""" Returns a generator of tweets that match a specified query.
|
""" Returns a generator of tweets that match a specified query.
|
||||||
|
|
@ -312,29 +321,14 @@ class Twython(object):
|
||||||
for tweet in content['results']:
|
for tweet in content['results']:
|
||||||
yield tweet
|
yield tweet
|
||||||
|
|
||||||
if 'page' not in kwargs:
|
try:
|
||||||
kwargs['page'] = 2
|
kwargs['page'] = 2 if not 'page' in kwargs else (int(kwargs['page']) + 1)
|
||||||
else:
|
except (TypeError, ValueError):
|
||||||
try:
|
raise TwythonError('Unable to generate next page of search results, `page` is not a number.')
|
||||||
kwargs['page'] = int(kwargs['page'])
|
|
||||||
kwargs['page'] += 1
|
|
||||||
kwargs['page'] = str(kwargs['page'])
|
|
||||||
except TypeError:
|
|
||||||
raise TwythonError("searchGen() exited because page takes type str")
|
|
||||||
|
|
||||||
for tweet in self.searchGen(search_query, **kwargs):
|
for tweet in self.searchGen(search_query, **kwargs):
|
||||||
yield tweet
|
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,
|
# The following methods are apart from the other Account methods,
|
||||||
# because they rely on a whole multipart-data posting function set.
|
# because they rely on a whole multipart-data posting function set.
|
||||||
|
|
||||||
|
|
@ -407,14 +401,6 @@ class Twython(object):
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
def getProfileImageUrl(self, username, size='normal', version='1'):
|
|
||||||
warnings.warn(
|
|
||||||
"This function has been deprecated. Twitter API v1.1 will not have a dedicated endpoint \
|
|
||||||
for this functionality.",
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=2
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stream(data, callback):
|
def stream(data, callback):
|
||||||
"""A Streaming API endpoint, because requests (by Kenneth Reitz)
|
"""A Streaming API endpoint, because requests (by Kenneth Reitz)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue