python-requests implemented
This commit is contained in:
parent
7334556248
commit
6325b16265
5 changed files with 54 additions and 15 deletions
|
|
@ -50,6 +50,24 @@ Example Use
|
||||||
# as skimming the source file. Both are kept human-readable, and are pretty well documented or
|
# as skimming the source file. Both are kept human-readable, and are pretty well documented or
|
||||||
# very self documenting.
|
# very self documenting.
|
||||||
|
|
||||||
|
Twython is now implemented using requests(http://python-requests.org).
|
||||||
|
from twythonrequests import Twython
|
||||||
|
|
||||||
|
twitter = Twython()
|
||||||
|
results = twitter.search(q='python')
|
||||||
|
|
||||||
|
# All the functions of twython is supported in twythonrequests.
|
||||||
|
Note:
|
||||||
|
Don't do this
|
||||||
|
from twython import Twython
|
||||||
|
from twythonrequests import Twython
|
||||||
|
|
||||||
|
instead try this
|
||||||
|
import twython
|
||||||
|
import twythonrequests
|
||||||
|
|
||||||
|
since you can hack both twython features.
|
||||||
|
|
||||||
A note about the development of Twython (specifically, 1.3)
|
A note about the development of Twython (specifically, 1.3)
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
As of version 1.3, Twython has been extensively overhauled. Most API endpoint definitions are stored
|
As of version 1.3, Twython has been extensively overhauled. Most API endpoint definitions are stored
|
||||||
|
|
|
||||||
17
README.txt
17
README.txt
|
|
@ -49,6 +49,23 @@ Example Use
|
||||||
# More function definitions can be found by reading over twython/twitter_endpoints.py, as well
|
# More function definitions can be found by reading over twython/twitter_endpoints.py, as well
|
||||||
# as skimming the source file. Both are kept human-readable, and are pretty well documented or
|
# as skimming the source file. Both are kept human-readable, and are pretty well documented or
|
||||||
# very self documenting.
|
# very self documenting.
|
||||||
|
Twython is now implemented using requests(http://python-requests.org).
|
||||||
|
from twythonrequests import Twython
|
||||||
|
|
||||||
|
twitter = Twython()
|
||||||
|
results = twitter.search(q='python')
|
||||||
|
|
||||||
|
# All the functions of twython is supported in twythonrequests.
|
||||||
|
Note:
|
||||||
|
Don't do this
|
||||||
|
from twython import Twython
|
||||||
|
from twythonrequests import Twython
|
||||||
|
|
||||||
|
instead try this
|
||||||
|
import twython
|
||||||
|
import twythonrequests
|
||||||
|
|
||||||
|
since you can hack both twython features.
|
||||||
|
|
||||||
A note about the development of Twython (specifically, 1.3)
|
A note about the development of Twython (specifically, 1.3)
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
3
setup.py
3
setup.py
|
|
@ -17,7 +17,8 @@ setup(
|
||||||
include_package_data = True,
|
include_package_data = True,
|
||||||
|
|
||||||
# Package dependencies.
|
# Package dependencies.
|
||||||
install_requires = ['simplejson', 'oauth2', 'httplib2'],
|
install_requires = ['simplejson', 'oauth2', 'httplib2', 'requests',
|
||||||
|
'oauth_hook'],
|
||||||
|
|
||||||
# Metadata for PyPI.
|
# Metadata for PyPI.
|
||||||
author = 'Ryan McGrath',
|
author = 'Ryan McGrath',
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,20 @@ import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import twythonrequests
|
import twythonrequests
|
||||||
|
twitter = twythonrequests.Twython()
|
||||||
|
|
||||||
class TestTwythonRequests(unittest.TestCase):
|
class TestTwythonRequests(unittest.TestCase):
|
||||||
def test_search(self):
|
def test_search(self):
|
||||||
twitter = twythonrequests.Twython()
|
|
||||||
result = twitter.search(q='python')
|
result = twitter.search(q='python')
|
||||||
self.assertTrue(result['results'])
|
self.assertTrue(result['results'])
|
||||||
|
|
||||||
|
def test_searchTwitter(self):
|
||||||
|
result = twitter.searchTwitter(q='python')
|
||||||
|
self.assertTrue(result['results'])
|
||||||
|
|
||||||
|
def test_getProfileImageUrl(self):
|
||||||
|
result = twitter.getProfileImageUrl(username='kracetheking')
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@ __version__ = "0.0.1"
|
||||||
requests supports 2.5 and above and no support for 3.x.
|
requests supports 2.5 and above and no support for 3.x.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import mimetypes
|
|
||||||
import mimetools
|
|
||||||
import re
|
|
||||||
import inspect
|
|
||||||
from urlparse import parse_qs
|
from urlparse import parse_qs
|
||||||
from urllib2 import HTTPError
|
from urllib2 import HTTPError
|
||||||
try:
|
try:
|
||||||
|
|
@ -446,15 +442,15 @@ class Twython(object):
|
||||||
url = "http://api.twitter.com/%s/users/profile_image/%s.json"%\
|
url = "http://api.twitter.com/%s/users/profile_image/%s.json"%\
|
||||||
(version, username)
|
(version, username)
|
||||||
try:
|
try:
|
||||||
self.response = requests.post(url, size=size)
|
self.response = requests.get(url, data={'size': size})
|
||||||
self.raise_for_status()
|
|
||||||
if self.response.status_code in (301, 302, 303, 307):
|
if self.response.status_code in (301, 302, 303, 307):
|
||||||
return self.response['location']
|
return self.response.headers['location']
|
||||||
else:
|
elif self.response.status_code == 200:
|
||||||
return json.loads(self.response.content)
|
return self.response.url
|
||||||
except:
|
self.raise_for_status()
|
||||||
return TwythonError("getProfileIMageUrl() failed with %d \
|
except HTTPError, e:
|
||||||
error code"% self.response.status_code)
|
raise TwythonError("getProfileIMageUrl() failed with %d \
|
||||||
|
error code"% `e.code`, e.code)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def unicode2utf8(text):
|
def unicode2utf8(text):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue