Merge branch 'master' of git@github.com:ryanmcgrath/tango
This commit is contained in:
commit
f2101405e9
3 changed files with 31 additions and 13 deletions
|
|
@ -63,8 +63,8 @@ class setup:
|
||||||
self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password)
|
self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password)
|
||||||
self.handler = urllib2.HTTPBasicAuthHandler(self.auth_manager)
|
self.handler = urllib2.HTTPBasicAuthHandler(self.auth_manager)
|
||||||
self.opener = urllib2.build_opener(self.handler)
|
self.opener = urllib2.build_opener(self.handler)
|
||||||
if self.headers is not None:
|
if headers is not None:
|
||||||
self.opener.addheaders = [('User-agent', self.headers)]
|
self.opener.addheaders = [('User-agent', headers)]
|
||||||
try:
|
try:
|
||||||
test_verify = simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json"))
|
test_verify = simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json"))
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Tango is an up-to-date library for Python that wraps the Twitter API.
|
NOTE: Tango is being renamed to Twython; all basic strings have been changed below, but there's still work ongoing in this department.
|
||||||
|
|
||||||
|
Twython is an up-to-date library for Python that wraps the Twitter API.
|
||||||
Other Python Twitter libraries seem to have fallen a bit behind, and
|
Other Python Twitter libraries seem to have fallen a bit behind, and
|
||||||
Twitter's API has evolved a bit. Here's hoping this helps.
|
Twitter's API has evolved a bit. Here's hoping this helps.
|
||||||
|
|
||||||
|
|
@ -15,7 +17,9 @@ import httplib, urllib, urllib2, mimetypes, mimetools
|
||||||
from urllib2 import HTTPError
|
from urllib2 import HTTPError
|
||||||
|
|
||||||
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
|
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
|
||||||
__version__ = "0.6"
|
__version__ = "0.8.0.1"
|
||||||
|
|
||||||
|
"""Twython - Easy Twitter utilities in Python"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import simplejson
|
import simplejson
|
||||||
|
|
@ -23,7 +27,7 @@ except ImportError:
|
||||||
try:
|
try:
|
||||||
import json as simplejson
|
import json as simplejson
|
||||||
except:
|
except:
|
||||||
raise Exception("Tango requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/")
|
raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import oauth
|
import oauth
|
||||||
|
|
@ -63,10 +67,10 @@ class setup:
|
||||||
self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password)
|
self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password)
|
||||||
self.handler = urllib2.HTTPBasicAuthHandler(self.auth_manager)
|
self.handler = urllib2.HTTPBasicAuthHandler(self.auth_manager)
|
||||||
self.opener = urllib2.build_opener(self.handler)
|
self.opener = urllib2.build_opener(self.handler)
|
||||||
if self.headers is not None:
|
if headers is not None:
|
||||||
self.opener.addheaders = [('User-agent', self.headers)]
|
self.opener.addheaders = [('User-agent', headers)]
|
||||||
try:
|
try:
|
||||||
test_verify = simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json"))
|
simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json"))
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
except HTTPError, e:
|
except HTTPError, e:
|
||||||
raise TangoError("Authentication failed with your provided credentials. Try again? (%s failure)" % `e.code`, e.code)
|
raise TangoError("Authentication failed with your provided credentials. Try again? (%s failure)" % `e.code`, e.code)
|
||||||
|
|
@ -86,6 +90,20 @@ class setup:
|
||||||
|
|
||||||
# URL Shortening function huzzah
|
# URL Shortening function huzzah
|
||||||
def shortenURL(self, url_to_shorten, shortener = "http://is.gd/api.php", query = "longurl"):
|
def shortenURL(self, url_to_shorten, shortener = "http://is.gd/api.php", query = "longurl"):
|
||||||
|
"""
|
||||||
|
function:: shortenURL(url_to_shorten, shortener, query)
|
||||||
|
|
||||||
|
Returns a shortened URL.
|
||||||
|
|
||||||
|
:param url_to_shorten: URL to shorten, as a String
|
||||||
|
:param shortener: URL to an API call for a different shortening service, allows overriding.
|
||||||
|
:param query: Name of the param that you pass the long URL as.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> twitter = tango.setup()
|
||||||
|
>>> twitter.shortenURL("http://webs.com/")
|
||||||
|
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return urllib2.urlopen(shortener + "?" + urllib.urlencode({query: url_to_shorten})).read()
|
return urllib2.urlopen(shortener + "?" + urllib.urlencode({query: url_to_shorten})).read()
|
||||||
except HTTPError, e:
|
except HTTPError, e:
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ except ImportError:
|
||||||
try:
|
try:
|
||||||
import json as simplejson
|
import json as simplejson
|
||||||
except:
|
except:
|
||||||
raise Exception("Tango requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/")
|
raise Exception("Tango requires a json library to work. http://www.undefined.org/python/")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import oauth
|
import oauth
|
||||||
|
|
@ -63,8 +63,8 @@ class setup:
|
||||||
self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password)
|
self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password)
|
||||||
self.handler = urllib.request.HTTPBasicAuthHandler(self.auth_manager)
|
self.handler = urllib.request.HTTPBasicAuthHandler(self.auth_manager)
|
||||||
self.opener = urllib.request.build_opener(self.handler)
|
self.opener = urllib.request.build_opener(self.handler)
|
||||||
if self.headers is not None:
|
if headers is not None:
|
||||||
self.opener.addheaders = [('User-agent', self.headers)]
|
self.opener.addheaders = [('User-agent', headers)]
|
||||||
try:
|
try:
|
||||||
test_verify = simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json"))
|
test_verify = simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json"))
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue