Also included is a twitter command-line tool for getting your friends'
tweets and setting your own tweet from the safety and security of your
-favorite shell and an IRC bot that can announce Twitter updated to an
+favorite shell and an IRC bot that can announce Twitter updates to an
IRC channel.
For more information:
from setuptools import setup, find_packages
import sys, os
-version = '0.4.2'
+version = '0.4.3'
setup(name='twitter',
version=version,
description="An API and command-line toolset for Twitter (twitter.com)",
- long_description="""\
-An API and command-line toolset for Twitter (twitter.com). Includes:
-
- * a lightweight Twitter API access class.
- * a twitter command-line tool for setting your status and getting your
- friends' status
- * a twitter IRC bot for announcing status updates to an IRC channel
-
-""",
+ long_description=open("./README", "r").read(),
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Development Status :: 5 - Production/Stable",
or self.uri.endswith('create')
or self.uri.endswith('destroy')):
method = "POST"
+
+ encoded_kwargs = urlencode(kwargs.items())
argStr = ""
- if kwargs:
- argStr = "?" + urlencode(kwargs.items())
+ if kwargs and (method == "GET"):
+ argStr = "?" + encoded_kwargs
+
+ headers = {}
+ if (self.username):
+ headers["Authorization"] = "Basic " + b64encode("%s:%s" %(
+ self.username, self.password))
+ if method == "POST":
+ headers["Content-type"] = "application/x-www-form-urlencoded"
+ headers["Content-length"] = len(encoded_kwargs)
+
c = httplib.HTTPConnection("twitter.com")
try:
- c.putrequest(method, "/%s.%s%s" %(
+ c.putrequest(method, "%s.%s%s" %(
self.uri, self.format, argStr))
- if (self.username):
- c.putheader(
- "Authorization", "Basic " + b64encode("%s:%s" %(
- self.username, self.password)))
- if (method == "POST"):
- # TODO specify charset
- pass
+ for item in headers.iteritems():
+ c.putheader(*item)
c.endheaders()
+ if method == "POST":
+ c.send(encoded_kwargs)
r = c.getresponse()
+
if (r.status == 304):
return []
elif (r.status != 200):
raise TwitterError("Twitter sent status %i: %s" %(
r.status, r.read()))
- if ("json" == self.format):
+ if "json" == self.format:
return json.loads(r.read())
else:
return r.read()
raise TwitterError("Unknown data format '%s'" %(format))
TwitterCall.__init__(self, email, password, format)
-__all__ = ["Twitter"]
+__all__ = ["Twitter", "TwitterError"]