python-requests implemented

This commit is contained in:
kracekumar 2011-12-06 21:38:04 +05:30
parent 7334556248
commit 6325b16265
5 changed files with 54 additions and 15 deletions

View file

@ -50,6 +50,24 @@ Example Use
# as skimming the source file. Both are kept human-readable, and are pretty well documented or
# 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)
----------------------------------------------------------------------------------------------------
As of version 1.3, Twython has been extensively overhauled. Most API endpoint definitions are stored

View file

@ -49,6 +49,23 @@ Example Use
# 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
# 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)
----------------------------------------------------------------------------------------------------

View file

@ -17,7 +17,8 @@ setup(
include_package_data = True,
# Package dependencies.
install_requires = ['simplejson', 'oauth2', 'httplib2'],
install_requires = ['simplejson', 'oauth2', 'httplib2', 'requests',
'oauth_hook'],
# Metadata for PyPI.
author = 'Ryan McGrath',

View file

@ -5,13 +5,20 @@ import json
import requests
import twythonrequests
twitter = twythonrequests.Twython()
class TestTwythonRequests(unittest.TestCase):
def test_search(self):
twitter = twythonrequests.Twython()
result = twitter.search(q='python')
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__":
unittest.main()

View file

@ -18,10 +18,6 @@ __version__ = "0.0.1"
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 urllib2 import HTTPError
try:
@ -446,15 +442,15 @@ class Twython(object):
url = "http://api.twitter.com/%s/users/profile_image/%s.json"%\
(version, username)
try:
self.response = requests.post(url, size=size)
self.raise_for_status()
self.response = requests.get(url, data={'size': size})
if self.response.status_code in (301, 302, 303, 307):
return self.response['location']
else:
return json.loads(self.response.content)
except:
return TwythonError("getProfileIMageUrl() failed with %d \
error code"% self.response.status_code)
return self.response.headers['location']
elif self.response.status_code == 200:
return self.response.url
self.raise_for_status()
except HTTPError, e:
raise TwythonError("getProfileIMageUrl() failed with %d \
error code"% `e.code`, e.code)
@staticmethod
def unicode2utf8(text):